Mind Design
Mind Design

Reputation: 41

Getting two values from same Joined table

I have two tables:

Table procedures has two columns

  1. destination_country_iso
  2. origin_country_iso

Table countries

  1. iso
  2. name

Im trying to join up the two tables in order to get both destination an origin country name from countries table.

SELECT *
FROM draft_procedures AS drp
LEFT JOIN countries AS c1 ON drp.destination_country_iso = c1.iso
LEFT JOIN countries AS c2 ON drp.origin_country_iso = c2.iso

The SQL result display proper result, but I now have two duplicate columns "name" and Im unable to retrieve them with the php code:

$destination_country=$row['c1.name']; 

Upvotes: 1

Views: 34

Answers (1)

ɹɐqʞɐ zoɹǝɟ
ɹɐqʞɐ zoɹǝɟ

Reputation: 4370

access it like this

SELECT drp.*,c1.name as c1name,c2.name as c2name
then
$row['c1name'] $row['c2name']

Upvotes: 2

Related Questions