We help IT Professionals succeed at work.

PHP SELECT *

Robert Granlund
on
81 Views
Last Modified: 2019-03-01
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

Comment
Watch Question

CERTIFIED EXPERT
Expert of the Year 2008
Top Expert 2008

Commented:
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

Author

Commented:
I was hoping there was a way around that.  There are a bunch of fields.
CERTIFIED EXPERT

Commented:
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.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2019
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions