groupbrand Posted July 4, 2012 Share Posted July 4, 2012 I have an issue when trying to retrieve results from an inner join query where the tables queried have column names. Basically if I inner join table1 with table2 and they both contain an id field, the query results return a table1.id and table2.id (along with any other column data requested). When I run through the results using mysql_fetch_assoc I can grab any unique column data but using $row['colname'] but I cannot get data from columns that have the same name e.g. $row['table1.id'] - can anyone point me in the right direction? Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/265193-getting-inner-join-result-data-when-column-names-are-the-same/ Share on other sites More sharing options...
trq Posted July 4, 2012 Share Posted July 4, 2012 Use an alias. eg; SELECT tbl1.col AS foo, tbl2.col AS bar Link to comment https://forums.phpfreaks.com/topic/265193-getting-inner-join-result-data-when-column-names-are-the-same/#findComment-1359079 Share on other sites More sharing options...
Barand Posted July 6, 2012 Share Posted July 6, 2012 But if you are doing an INNER JOIN on the id columns and they both have the same value, why would you need to select both of them? Link to comment https://forums.phpfreaks.com/topic/265193-getting-inner-join-result-data-when-column-names-are-the-same/#findComment-1359781 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.