identical named field names in multiple tables

identical named field names in multiple tables

am 11.11.2005 00:43:38 von Dave Smith

I am joining three tables all of which contain the same field name.
example:
CLNT_STATS_YTD.Vol_Collected
CLNT_STATS_MTD.Vol_Collected
CLNT_STATS_TD.Vol_Collected

If I try to reference them using those names I get no data. If I use the
last half "Vol_Collected" I get the last value of the three. I'm not
sure how to reference them seperately in php. Thank you for any help.

Dave

Re: identical named field names in multiple tables

am 11.11.2005 01:09:13 von zeldorblat

One way is to fetch the row as a numerically-indexed array and use the
numeric keys. The preferred (and much better) way is to alias the
column names in your query. So something like this:

CLNT_STATS_YTD.Vol_Collected as YTD_Vol_Collected
CLNT_STATS_MTD.Vol_Collected as MTD_Vol_Collected
CLNT_STATS_TD.Vol_Collected as TD_Vol_Collected

Then, when you fetch the result, you can refer to the columns as
YTD_Vol_Collected, MTD_Vol_Collected, etc.

Re: identical named field names in multiple tables

am 11.11.2005 01:10:21 von IchBin

Dave Smith wrote:
> I am joining three tables all of which contain the same field name.
> example:
> CLNT_STATS_YTD.Vol_Collected
> CLNT_STATS_MTD.Vol_Collected
> CLNT_STATS_TD.Vol_Collected
>
> If I try to reference them using those names I get no data. If I use the
> last half "Vol_Collected" I get the last value of the three. I'm not
> sure how to reference them seperately in php. Thank you for any help.
>
> Dave
What does your SQL statement look like..

--


Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
____________________________________________________________ ______________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)

Re: identical named field names in multiple tables

am 11.11.2005 01:28:01 von Dave Smith

That worked! Thank you very much!
Dave

In article <1131667753.659031.233300@f14g2000cwb.googlegroups.com>,
"ZeldorBlat" wrote:

> One way is to fetch the row as a numerically-indexed array and use the
> numeric keys. The preferred (and much better) way is to alias the
> column names in your query. So something like this:
>
> CLNT_STATS_YTD.Vol_Collected as YTD_Vol_Collected
> CLNT_STATS_MTD.Vol_Collected as MTD_Vol_Collected
> CLNT_STATS_TD.Vol_Collected as TD_Vol_Collected
>
> Then, when you fetch the result, you can refer to the columns as
> YTD_Vol_Collected, MTD_Vol_Collected, etc.

Re: identical named field names in multiple tables

am 11.11.2005 18:24:16 von jds

On Thu, 10 Nov 2005 15:43:38 -0800, Dave Smith wrote:

> I am joining three tables all of which contain the same field name.
> example:
> CLNT_STATS_YTD.Vol_Collected
> CLNT_STATS_MTD.Vol_Collected
> CLNT_STATS_TD.Vol_Collected
>
> If I try to reference them using those names I get no data. If I use the
> last half "Vol_Collected" I get the last value of the three. I'm not
> sure how to reference them seperately in php. Thank you for any help.
>
> Dave

I'm sure somebody already answered this, but here goes...

You have to use column "aliases" in the SQL statment:

SELECT CLNT_STATS_YTD.Vol_Collected as "ytd_collected"
, CLNT_STATS_MTD.Vol_Collected as "mtd_collected"
, CLNT_STATS_TD.Vol_Collected as "td_collected"
FROM whatever;

--
JDS | jeffrey@example.invalid
| http://www.newtnotes.com
DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/