I'm struggling with some logic here.
In my MySQL database I have a table that looks like this:
id | lower | upper
1 | 0 | 120
2 | 121 | 200
3 | 201 | 500
Now, my form posts two values e.g. 121 and 300.
What query can get those rows where 121 to 300 overlap the lower and upper columns?
In this example these rows are: 2 and 3
I just can't figure it开发者_Python百科 out..
SELECT *
FROM table
WHERE (121 <= lower AND 300 >= lower) OR (121 <= upper AND 300 >= upper)
This works perfectly
SELECT * FROM Table1
WHERE lower <= 300 AND upper >= 121
精彩评论