I have two tables with the following schema:
data | hora ini | hora fim
-----------|------------|---------
16/08/2016 | 1115 | 1319
16/08/2016 | 1320 | 1419
16/08/2016 | 1420 | 90
In the second table, it already has the records entered every half hour, as in the example below:
data | hora
-----------|-------
16/08/2016 | 1380
16/08/2016 | 1410
17/08/2016 | 0
17/08/2016 | 30
17/08/2016 | 60
17/08/2016 | 90
17/08/2016 | 120
What I need is that when I update a record from the second table, for example the midnight record, it does a search if there is no record in the first table that "runs between 00:00 and 00:30 ". That is, if there is a period indicated in the first table that is from 10:00 p.m. to 1:00 p.m., it should appear in this select.
I can mount a BETWEEN to return the records, however, when it passes midnight it buga because the final hour ends up being smaller than the initial one.