I have table SOME_TABLE
id date_start date_end
0 05.01.2017 09.01.2017
...
I need select for get all rows where my new date_start and new date_end with Intersection.
if
new date_start = 01.01.2017 and new date_end 10.01.2017
or new date_start = 06.01.2017 and new date_end 06.01.2017
or new date_start = 01.01.2017 and new date_end 06.01.2017
or new date_start = 08.01.2017 and new date_end 10.01.2017
I need get this rows and if
new date_start = 22.12.2016 and new date_end 31.12.2016
or new date_start = 15.01.2017 and new date_end 22.01.2017
I need not select this rows.
I create select but it not work
select *
from SOME_TABLE t
where (to_date('02.04.2017', 'dd.MM.yyyy') >= t.date_start AND
to_date('02.04.2017', 'dd.MM.yyyy') <= t.date_end)
OR to_date('11.04.2017', 'dd.MM.yyyy') > t.date_start
if date not Intersection this select return rows does not matter
EDIT if this answer:
If start and end dates can be out of order, i.e., if it is possible that startA > endA or startB > endB, then you also have to check that they are in order, so that means you have to add two additional validity rules: (StartA <= EndB) and (StartB <= EndA) and (StartA <= EndA) and (StartB <= EndB) or: (StartA <= EndB) and (StartA <= EndA) and (StartB <= EndA) and (StartB <= EndB) or, (StartA <= Min(EndA, EndB) and (StartB <= Min(EndA, EndB)) or: (Max(StartA, StartB) <= Min(EndA, EndB)
How can I Remake my select like it?