I would like to insert a new price range in a table but before I need to check if my price range is already included or part of any other price range.
Here is an example:
My price range table:
| minimum | maximum |
---------------------
| 1 | 100 |
| 201 | 300 |
| 301 | 400 |
- If I submit [50,200], I must reject it because 50 is included in the range [1,100].
- If I submit [175,201], I must reject it because 201 is included in the range [201,300].
- If I submit [350,380], I must reject it because 350 and 380 are included in the range [301,400].
- If I submit [120,190], I must accept it because 120 and 190 are not included in any range.
My question is how to check with MySQL if the submitted range is included or not in my table.
This should work (assuming the table is called
rangesand the new range parameters are @low and @high respectively):Of course, this could be further coalesced/condensed:
And even further: