Reputation: 111
I need to check for the following condition:
lower_limit <= VALUE < upper_limit
I can do the above using
Model.where("lower_limit <= ? AND upper_limit > ?", value, value)
but how do I do the same using ranges ? (..)/(...)
Please note the operators:
The first operator of between is "<=" and second operator is ">". Had they been same, I could have used (..) or (...).
Upvotes: 1
Views: 132
Reputation: 1885
You cannot do that with a range in the query, but you can still make use of BETWEEN
. In MySQL, BETWEEN
is inclusive. You could write something like:
Model.where("? BETWEEN lower_limit AND upper_limit - 1", value)
Which would generate SQL like:
SELECT * FROM models WHERE (37 BETWEEN lower_limit AND upper_limit - 1)
Upvotes: 0