Reputation: 872
I have an sql statement like this:
SELECT * FROM USERS WHERE USER_ID IN (SELECT REQUEST_FROM FROM REQUESTS WHERE REQUEST_TO = '$user_id' ORDER BY REQUEST_ID ASC);
This statement returns the user informations from users table, where user's id is in REQUEST_FROM.
I also have REQUEST_DATE in REQUESTS table. I would like to order the results of this statement by REQUEST_DATE.
I don't know if this information is enough for you. I can give extra information about sql.
Upvotes: 1
Views: 295
Reputation: 1270713
Use an explicit join
instead of in
:
SELECT u.*
FROM USERS u JOIN
REQUESTS r
ON u.USER_ID = r.REQUEST_FROM
WHERE r.REQUEST_TO = '$user_id'
ORDER BY r.REQUEST_DATE ASC;
Upvotes: 0
Reputation: 1883
Try this code:
SELECT u.*
FROM USERS u , REQUESTS r
WHERE (r.REQUEST_TO = '$user_id') and (u.USER_ID = r.REQUEST_FROM)
ORDER BY r.REQUEST_DATE ASC;
Upvotes: 1