我想从表中发布同一个查询中评价最高的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
答案 0 :(得分:1)
尝试UNION
(SELECT id FROM posts ORDER BY rates DESC LIMIT 0,8)
UNION ALL
(SELECT id FROM posts ORDER BY views DESC LIMIT 0,8)