Re: Join table with clashing fieldnames

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have an SQL query which has a simple join, this works and is fine the fields from the secondary table are added to the returned array. But what happens if I add another JOIN to a table which has fields which are the same name? Is there any way to have PHP prefix the key's (fieldnames) of the joined fields?

You'll need to create an alias for the conflicting fields.

SELECT
 Table1.ConflictingField AS Table1_ConflictingField,
 Table2.ConflictingField AS Table2_ConflictingField
FROM
 Table1
INNER JOIN Table2 ON Table2.FK = Table2.PK

Or something like that.  Just doing "SELECT *" isn't best practice[1].

thnx,
Chris

[1] Though I'm terribly guilty of doing that way more often than I should be...
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux