我们有2个选择sql查询:
SELECT id, username, group_id, score FROM users WHERE status=1 AND
active=1 AND id != 9 AND score >= 100 ORDER BY score DESC LIMIT 2;
和
SELECT id, username, group_id, score FROM users WHERE status=1 AND
active=1 AND id != 9 AND score <= 100 ORDER BY score DESC LIMIT 2;
如何通过1 sql查询选择它们?
这是一个MySQL数据库。
答案 0 :(得分:0)
使用union all
代替
(SELECT id, username, group_id, score FROM users WHERE status=1 AND
active=1 AND id != 9 AND score >= 100 ORDER BY score DESC LIMIT 2)
union all
(SELECT id, username, group_id, score FROM users WHERE status=1 AND
active=1 AND id != 9 AND score <= 100 ORDER BY score DESC LIMIT 2)