PHP SQL按其他表排序

时间:2013-06-28 03:21:17

标签: php sql select sql-order-by

我希望能够从数据库的内部选择中订购列表。我的代码:

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

我希望能够从表last而不是users获取订单。

1 个答案:

答案 0 :(得分:1)

试试这个,

使用JOIN查询

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