How do you specify a field in a table join that has the same name as another field?

This is a discussion on How do you specify a field in a table join that has the same name as another field? within the PHP Language forums, part of the PHP Programming Forums category; I have joined two tables in a SQL statement and retrieved the recordset using mysql_fetch_assoc. Now how do I refer ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-07-2007
gentleJuggernaut
 
Posts: n/a
Default How do you specify a field in a table join that has the same name as another field?

I have joined two tables in a SQL statement and retrieved the
recordset using mysql_fetch_assoc. Now how do I refer to a field
called time_stamp from table A when there is a field called
time_stamp in table B. I have tried things like
$row['A.time_stamp']; but it does not seem to work. Can anyone direct
me to the appropriate documentation?

Thanks,

NSM

Reply With Quote
  #2 (permalink)  
Old 08-07-2007
ZeldorBlat
 
Posts: n/a
Default Re: How do you specify a field in a table join that has the same name as another field?

On Aug 7, 10:08 am, gentleJuggernaut <url...@gmail.com> wrote:
> I have joined two tables in a SQL statement and retrieved the
> recordset using mysql_fetch_assoc. Now how do I refer to a field
> called time_stamp from table A when there is a field called
> time_stamp in table B. I have tried things like
> $row['A.time_stamp']; but it does not seem to work. Can anyone direct
> me to the appropriate documentation?
>
> Thanks,
>
> NSM


You alias it to something else in the query itself:

select a.timestamp as timestampA, b.timestamp as timestampB
from a, b
where a.id = b.id

Then refer to it by its aliased name:

$row['timestampA']

Reply With Quote
  #3 (permalink)  
Old 08-07-2007
gentleJuggernaut
 
Posts: n/a
Default Re: How do you specify a field in a table join that has the same name as another field?

On Aug 7, 10:19 am, ZeldorBlat <zeldorb...@gmail.com> wrote:
> On Aug 7, 10:08 am, gentleJuggernaut <url...@gmail.com> wrote:
>
> > I have joined two tables in a SQL statement and retrieved the
> > recordset using mysql_fetch_assoc. Now how do I refer to a field
> > called time_stamp from table A when there is a field called
> > time_stamp in table B. I have tried things like
> > $row['A.time_stamp']; but it does not seem to work. Can anyone direct
> > me to the appropriate documentation?

>
> > Thanks,

>
> > NSM

>
> You alias it to something else in the query itself:
>
> select a.timestamp as timestampA, b.timestamp as timestampB
> from a, b
> where a.id = b.id
>
> Then refer to it by its aliased name:
>
> $row['timestampA']


thanks

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:03 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0