How can I join these two select statements?

190
June 08, 2017, at 08:51 AM

First statement

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

Second statement

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

I don't know for sure if this is what you're looking for, but you can UNION them.

(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)
Answer 2

Wouldnt the "obvious" solution be to do this:

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

or alternative like Remco mentioned with between:

SELECT * FROM `file` WHERE Region = 'x' AND NOT (level BETWEEN 2 AND 3) ORDER by id DESC LIMIT 0,6
READ ALSO
Does it make sense to use a timestamp before saving or when saving to database

Does it make sense to use a timestamp before saving or when saving to database

Question is pretty forward and it is bothering me for quite some time nowPerhaps any of you has an interesting view on this matter

150
mysql error (HY000):file not found (Errcode: 2)

mysql error (HY000):file not found (Errcode: 2)

So I'm trying to load my database by loadingtxt file (fields terminated by \t)

313
MySQL - Keep finding superiors of employees until the most superior employee is reached

MySQL - Keep finding superiors of employees until the most superior employee is reached

I have an employees table in which all employees report to a superior except for one employee who reports to no one as he is the boss

164