I have two tables and they are as follows:
USERS
ORDERS
I want select all users who have at least 1 order or more in the ORDERS table. I know there is an inline query for this in MySQL, but right now I have to select all users and then make another query seeing if each user has an order – all this using a PHP loop.
What I am doing now is not ethically correct, so I basically just want to select all users who have been referenced in the ORDERS table in ONE MySQL query.
This is a query you should be using
Note the
distinctandu.*. This query will not select fields fromordersand it will not select the same user twice (if one has more than one order).Demo: http://sqlfiddle.com/#!2/6ebcc/3