Canman2005 Posted December 9, 2008 Share Posted December 9, 2008 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 Link to comment https://forums.phpfreaks.com/topic/136246-distinguishing-duplicate-field-names-in-select-query/ Share on other sites More sharing options...
rhodesa Posted December 9, 2008 Share Posted December 9, 2008 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']; Link to comment https://forums.phpfreaks.com/topic/136246-distinguishing-duplicate-field-names-in-select-query/#findComment-710723 Share on other sites More sharing options...
Canman2005 Posted December 9, 2008 Author Share Posted December 9, 2008 thanks dude Link to comment https://forums.phpfreaks.com/topic/136246-distinguishing-duplicate-field-names-in-select-query/#findComment-710763 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.