I have two columns: amountFrom
, amountTo
in table shipping
Lets say I have these row data:
amountFrom | amountTo
-----------------------
0 15
16 30
31 50
Now I would like to add these three:
amountFrom | amountTo
-----------------------
15 22 (should fail, already exist (crosses range))
18 25 (should fail, already exist)
55 76 (should pass)
How can I make a correct sql query, that will run for each row i would like to insert, that will check if the "range" is available?
Example of what i tried
SELECT id FROM shipping WHERE amountFrom >= 15 AND amountTo <= 22
Above query returns no rows, which it should (if it was a correct query) since we dont want to make a new row with 15 and 22, as it will cross existing weight ranges