Link to home
Start Free TrialLog in
Avatar of Robert Granlund
Robert GranlundFlag for United States of America

asked on

PHP SELECT *

PHP SELECT * .  I am performing a query on two tables and they both have a column user  They both are associated by their ID.  I want to give table 1 user the alias user and table two the alias alt_user .  How do I do that?
This is wrong but it will help:

 $sql = "SELECT * dd.user AS user, oi.user AS alt_user FROM data dd JOIN orders oi ON dd.id=oi.id  WHERE dd.name LIKE :term";

Open in new window

Avatar of hielo
hielo
Flag of Wallis and Futuna image

Instead of select *, you will need to list all the fields that you want from each dd and oi, not just the user aliases:

//assuming that dd has a column named customer_name:
$sql = "SELECT  dd.user AS user, oi.user AS alt_user,  dd.id, dd.customer_name FROM data dd JOIN orders oi ON dd.id=oi.id  WHERE dd.name LIKE :term";

Open in new window

Avatar of Robert Granlund

ASKER

I was hoping there was a way around that.  There are a bunch of fields.
I was hoping there was a way around that.  There are a bunch of fields.
workaround would be named your fields uniquely in these 2 tables, else you gonna write the Select query to explicitly select and liaise the fields when necessary.
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial