我如何加入这两个选择语句?

时间:2017-06-07 22:30:24

标签: mysql sql

第一句话

SELECT * FROM `file` WHERE Region = 'x' AND level > 2 ORDER by id DESC LIMIT 0,6

第二个陈述

SELECT * FROM `file` WHERE Region = 'x' AND level < 3 ORDER by id DESC LIMIT 0,6

2 个答案:

答案 0 :(得分:2)

我不确定这是否是您正在寻找的,但您可以将它们联合起来。

(SELECT * FROM `file` WHERE Region = 'x' AND level > 2 ORDER by id DESC LIMIT 0,6)
UNION
(SELECT * FROM `file` WHERE Region = 'x' AND level < 3 ORDER by id DESC LIMIT 0,6)

答案 1 :(得分:2)

“显而易见”的解决方案不是这样做的:

SELECT * FROM `file` WHERE Region = 'x' AND (level > 2 OR level < 3) ORDER by id DESC LIMIT 0,6

或像Remco之间提到的替代方案:

SELECT * FROM `file` WHERE Region = 'x' AND NOT (level BETWEEN 2 AND 3) ORDER by id DESC LIMIT 0,6