Jump to content

Distinguishing duplicate field names in SELECT QUERY


Canman2005

Recommended Posts

Hi all

 

I have the following QUERY

 

SELECT DISTINCT(log.dates), log.type, prod1.net_cost,prod1.vat,prod2.net_cost,prod2.vat FROM mstlog

 

As you can see, I have field with that have duplicate names, they are

 

prod1.net_cost,prod1.vat

 

and

 

prod2.net_cost,prod2.vat

 

When I want to output, I use

 

print $row['net_cost'];

 

But as I have the field `net_cost` in both tables, it's impossible for it to distinguish between the `net_cost` fields.

 

Is there a way to overcome this?

 

Can you do something like

 

prod1.TBL1.net_cost,prod1.TBL1.vat

print $TBL1.row['net_cost'];

 

prod2.TBL2.net_cost,prod2.TBL2.vat

print $TBL2.row['net_cost'];

 

Thanks

 

Ed

use the AS clause in the query:

SELECT DISTINCT(log.dates), log.type, prod1.net_cost AS prod1_net_cost,prod1.vat AS prod1_vat,prod2.net_cost AS prod2_net_cost,prod2.vat AS prod2_vat FROM mstlog

then

echo $row['prod1_net_cost'];

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.