I have looked at a lot of solutions here, but can't get any of them to work in my situation. I'm beyond my SQL skill level here for sure.
I have a table that holds class beginning and end date/times for each class session:
Table: class_times
Columns:
time_class_id
time_end
time_start
time_end
and time_start
are Unix timestamps
.
When a student puts a class in the cart I have to check and make sure that there are no time conflicts with any other classes in the cart. It's a time range. Could be a 4 hour class or a 2 hour class. If there is any time conflict I have to alert the student. The time_class_id is the class which could easily have a dozen rows of dates/times and different ones at that.
This is the closest I've gotten but this seems to only find conflicts where the start and end times are exactly the same:
SELECT a.time_class_id, a.time_start, a.time_end,
b.time_class_id, b.time_start, b.time_end
FROM class_times a, class_times b
WHERE a.time_class_id in ($classes_in_cart)
AND b.time_class_id in ($classes_in_cart)
AND (a.time_class_id <> b.time_class_id
AND a.time_start >= b.time_start AND
a.time_end <= b.time_end)
Any help would be greatly appreciated.