MYSQL - Conflict Time Check

I currently have this table 'tbl_subloading':

teacher_name  |  start_time   |  end_time  
de Guzman, J  |  08:00AM      |  10:00AM
Harris, M     |  07:00AM      |  09:00AM

I want my program to find that the schedule assigned to a particular teacher already overlaps the existing schedule. For example, "de Guzman, J" can no longer be a class from 9 AM to 11 AM, as it is no longer available.

I tried this request, which I saw from another thread:

SELECT (COUNT(*) = 0) AS Available FROM tbl_subloading 
WHERE `teacher_name` = 'de Guzman, J' 
AND ( (start_time <= '07:00AM' AND end_time >= '07:00AM') 
OR (start_time <= '08:00AM' AND end_time >= '08:00AM'));

This query outputs 1 if it is available for that specific period, 0 if not. For example, if de Guzman, J is given a schedule from 12 to 13 hours, he displays 1. But if de Guzman, J is provided a schedule from 10 to 11 hours, he displays 0, although it is already available for this period.

Is there an alternative you could make of this?

Thanks in advance.

+4
1

BETWEEN .

 SELECT (COUNT(*)) AS Available 
 FROM tbl_subloading 
 WHERE teacher_name = 'de Guzman, J' 
 AND ( (start_time BETWEEN '07:00AM' AND '08:00AM') OR (start_time BETWEEN '08:00AM' AND '09:00AM')) 

de Guzman, J , 0. , , , 1,2. , OR.

, BETWEEN . .

+4

Source: https://habr.com/ru/post/1686517/


All Articles