I want to create a query that inserts data to a table and checks if my date range overlaps the already existing date ranges.
I created the following working query but it inserts 2 rows with the same data. Can you find anything wrong in it?
INSERT INTO infoscreen_times (screen_id, start, end, view_id)
SELECT ?, ?, ?, ?
FROM infoscreen_screens
WHERE EXISTS (
SELECT id
FROM infoscreen_times
WHERE ? BETWEEN start AND end
AND screen_id = ?
OR ? BETWEEN start AND end
AND screen_id = ?
OR ? <= start
AND ? >= end
AND screen_id = ?) IS FALSE
start means the Start-Timestamp, end is the End-Timestamp. In the Subquery i want the check if the timestamps i want to insert overlap each other. If they do i want to get a error and if they dont the query insert the data.
Thanks in advance.