我想从表中获得 8 个评价最高的帖子(posts.rates)和 8 个观看次数最多的帖子(posts.views),所以我得到了 16 个结果。两个字段都在同一张表上。所以为时已晚,实际上无法弄清楚该怎么做。提前致谢。
我不想在一个查询中做类似下面的事情,得到 16 行:
SELECT id FROM posts
ORDER BY rates DESC
LIMIT 0,8;
SELECT id FROM posts
ORDER BY views DESC
LIMIT 0,8;
编辑:答案:
SELECT id FROM (SELECT id FROM posts ORDER BY views DESC LIMIT 0,8) AS a
UNION ALL
SELECT id FROM (SELECT id FROM posts ORDER BY rates DESC LIMIT 0,8) AS b