Brian
Brian

Reputation: 151

PHP SQL order by other table

I want to be able to order the list from the inner select from the database. My code:

$sql = "SELECT * from `users` WHERE `name` in (select `last` from info where `date` = '2013' ORDER BY  `id` DESC)";

I want to be able to get the order from table last instead of users.

Upvotes: 0

Views: 55

Answers (1)

Nikhil Mohan
Nikhil Mohan

Reputation: 891

Try this,

Use JOIN query

$sql = "SELECT u.* from `users` u JOIN `info` i ON u.name = i.last WHERE i.date = '2013' ORDER BY i.id DESC";

Upvotes: 1

Related Questions