I have a table that has min
and max
columns. I want to search for rows where a set of numbers are between this range of min
and max
.
Example: I have a set (3, 4, 11, 18)
.
My query filtering could look:
(3 between min and max) OR
(4 between min and max) OR
(11 between min and max) OR
(18 between min and max)
But I wanted to know if there is a better way something like:
(3,4,11,12) between min and max
that will do similar to #1
I need this because the set can change between different searches. Any help or suggestions are appreciated.
The table in simpler context is class (classid, classname, minage, maxage). There are thousands of classes - so I get web request searching for classes with specific set of ages for example (3,4,11,12) where a user is searching for classes for ages 3, 4, 11 and 12.
Currently my query looks: select * from class where ((3 between min and max) OR (4 between min and max) OR (11 between min and max) OR (18 between min and max))
Something like
SELECT *
FROM MyTable AS T
WHERE EXISTS (
SELECT *
FROM MySet AS S
WHERE S.val BETWEEN T.my_min AND T.my_max
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With