Avatar of Robert Granlund
Robert Granlund
Flag 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

PHP

Avatar of undefined
Last Comment
Julian Hansen

8/22/2022 - Mon
hielo

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

Robert Granlund

ASKER
I was hoping there was a way around that.  There are a bunch of fields.
Ryan Chong

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.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER CERTIFIED SOLUTION
Julian Hansen

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.