是否可以在1 sql select中选择这些查询?

时间:2015-03-04 11:41:54

标签: mysql sql

我们有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数据库。

1 个答案:

答案 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)