I am working on a new application and suddenly got stuck on an easy at first sight task.
I have a datatype called “Commission” (2 fields “from” and “to” - all type “number”). Also there is a button for saving inputs mentioned above to the DB (create a new Commission).
Now I wan’t to add a check BEFORE saving a new Commission to the DB. I need to check whether there are any existing Commissions in the DB that intersect with a new one I’m trying to create. Intersection should be determined using a number range, where FROM is the minimal value of the range and TO is the maximum value of the range.
Example, I have 3 commissions in the DB:
FROM - TO
1 - 10
11 - 20
21 - 30
The check should work in the following way:
- 31 - 40 should be saved successfully (no intersections with existing commissions)
- 30 - 40 should not be saved (intersection with 1 commission from the DB)
- 9 - 32 should not be saved (intersection with 3 commissions from the DB)
Any help will be appreciated!