Re: Join table with clashing fieldnames

From: Date: Wed, 08 Nov 2006 13:26:57 +0000
Subject: Re: Join table with clashing fieldnames
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-244369@lists.php.net to get a copy of this message
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...

« previous php.general (#244369) next »