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

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

am 07.08.2007 16:08:52 von gentleJuggernaut

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

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

am 07.08.2007 16:19:41 von zeldorblat

On Aug 7, 10:08 am, gentleJuggernaut 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']

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

am 07.08.2007 16:38:48 von gentleJuggernaut

On Aug 7, 10:19 am, ZeldorBlat wrote:
> On Aug 7, 10:08 am, gentleJuggernaut 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

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

am 07.08.2007 22:49:34 von unknown

Post removed (X-No-Archive: yes)