I have a table X with records:
rec# start end
===============
100 2000 2020
101 2004 2005
102 2006 2007
I try:
SELECT * from X where start >= 2004 and end <= 2005;
and
SELECT * from X where start BETWEEN 2004 and 2005;
In both cases I (correctly) get rec# 101 as the result.
But I need to also be retrieving rec# 100 because the range (2004-2005) is included in the 2000-2020 record.
Thank you for any help…
Sounds like you have your inequalities around the wrong way:
This will return all records which contain the interval
[2004,2005].See it on sqlfiddle.