How can you access two identically-named columns in a MySQL LEFT JOIN query?
Posted
by George Edison
on Stack Overflow
See other posts from Stack Overflow
or by George Edison
Published on 2010-03-26T22:09:29Z
Indexed on
2010/03/26
22:23 UTC
Read the original article
Hit count: 235
I have two tables.
table_x:
id INT(11)
tag INT(11)
table_tags:
id INT(11)
name VARCHAR(255)
Then I use PHP to perform the following query:
SELECT * FROM table_x LEFT JOIN table_tags ON table_x.tag = table_tags.id
The only problem is: how do I access table_x.id
and table_tags.id
in the results?
Here is the PHP code:
$query = "SELECT * FROM table_x LEFT JOIN table_tags ON table_x.tag = table_tags.id";
$results = mysql_query($query);
while($row = mysql_fetch_array($results))
{
// how do I now access table_x.id and table_tags.id ???
}
© Stack Overflow or respective owner