I have following database schema (where day value 0=mon,1=tue,2=wed
and so on)
And the following input
{
"day": 3,
"start_time": "15:00",
"end_time": "17:30"
},
{
"day": 5
"start_time": "08:00",
"end_time": "12:00"
}
I want to find if input value contains any overlapping record from the database. (note that in my case, I can have multiple start_time, end_time for a given day)
Here is what I tried.
SELECT
COUNT(id) AS total_count
FROM
working_hour
WHERE (
(day = 3 AND (start_time <= '15:00' AND end_time >= '17:30')) ||
(day = 5 AND (start_time <= '08:00' AND end_time >= '12:00'))
) AND user_id = 1;
This return me total count of 0
whereas I am expecting 1
because on day = 3
we have a matching overlapping record with id 5
Where am I going wrong here?
Thank you.