Re: [PHP] mySQL / PHP Join Question

2001-09-09 Thread David Robley

On Sun,  9 Sep 2001 13:34, Dana Holt wrote:
> I have a query that uses a LEFT JOIN, but the two tables have some
> columns with the same name. How can I tell the columns from each table
> apart? It seems that the "joined" table overwrites the values from the
> other table.
>
> Anyone know?
>
> Thanks.
>
> --
> Dana Holt / [EMAIL PROTECTED]

Describe them as tablename.fieldname and you may want to alias them so 
you can differentiate in PHP. For example, if you have tables 'person' 
and 'place', both with a field 'description', you could use something like

SELECT person.description AS pdesc, place.description AS wdesc FROM 
person, place WHERE 

-- 
David Robley  Techno-JoaT, Web Maintainer, Mail List Admin, etc
CENTRE FOR INJURY STUDIES  Flinders University, SOUTH AUSTRALIA  

   "I was the first to climb Mount Everest," said Tom hilariously.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] mySQL / PHP Join Question

2001-09-08 Thread Don Read


On 09-Sep-2001 Dana Holt wrote:
> 
> I have a query that uses a LEFT JOIN, but the two tables have some columns
> with the same name. How can I tell the columns from each table apart? It
> seems that the "joined" table overwrites the values from the other table.
> 

If the column is part of the join criterion, it won't matter.

otherwise, alias the column name:

SELECT t1.id as siteid, t2.id as wmid, t2.name as name
FROM site as t1 LEFT JOIN webmaster as t2 USING (id)
WHERE t2.name is NOT NULL ...

Regards,
-- 
Don Read   [EMAIL PROTECTED]
-- It's always darkest before the dawn. So if you are going to 
   steal the neighbor's newspaper, that's the time to do it.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]