I need to get the overlapping date row from DB where my entered start and end dates overlaps with any of the rows in the DB.
Query:
SELECT *
FROM dates
WHERE date_from >= $dateFrom
AND date_from >= $dateTill
OR date_till >= $dateFrom
AND date_till <= $dateTill
OR date_from <= $dateFrom
AND date_till >= $dateTill
Currently I have a row with start date: 2019-03-11 and end date 2019-03-17
And query skips it at the moment with these dates:
Beginning: 2019-03-07
End: 2019-03-16
Any ideas how can I improve the query?