I'm working on a calendar app that allows double booking and overlapping meetings to be entered. We're trying to build a web page that shows all overlapping meetings so they can be resolved manually (cancelled, rescheduled, ignored, etc.).
Just to be clear, we WANT to allow conflicting dates to be entered. What we're trying to do is find all of them after they were entered.
Here's a stripped down copy of my meetings
table:
CREATE TABLE `meetings` (
`id` INT(10) NOT NULL AUTO_INCREMENT,
`is_all_day` TINYINT(1) UNSIGNED NULL DEFAULT NULL,
`date` DATE NOT NULL,
`start_time` TIME NULL DEFAULT NULL,
`end_time` TIME NULL DEFAULT NULL,
PRIMARY KEY (`id`)
);
INSERT INTO `meetings` (`id`, `is_all_day`, `date`, `start_time`, `end_time`) VALUES
(1, NULL, '2021-08-08', '06:00:00', '09:00:00'),
(2, NULL, '2021-08-09', '06:00:00', '09:00:00'),
(3, NULL, '2021-08-10', '06:00:00', '09:00:00'),
(4, NULL, '2021-08-11', '06:00:00', '09:00:00'),
(5, NULL, '2021-08-12', '06:00:00', '09:00:00'),
(6, NULL, '2021-08-13', '06:00:00', '09:00:00'),
(7, NULL, '2021-08-14', '06:00:00', '09:00:00'),
(8, NULL, '2021-08-10', '08:00:00', '08:30:00'),
(9, NULL, '2021-08-11', '08:00:00', '08:30:00'),
(10, NULL, '2021-08-12', '08:00:00', '08:30:00'),
(11, NULL, '2021-08-10', '06:45:00', '08:45:00'),
(12, 1, '2021-08-12', NULL, NULL),
(13, 1, '2021-08-14', NULL, NULL);
Meetings can only occur on a single day between 12am and 11:59am, in other words they won't run into the next day (e.g. 10pm to 2am). The is_all_day
column is a boolean flag for if the meeting runs all day.
If there are 2 or more meetings in the database that overlap each other, I would expect the query to return all of them. It's not important to know which meeting(s) they overlap with but if possible, that would be great.
With this data, I'd expect all rows to be returned except the first two, as they don't overlap any other meetings. Here's a visual:
I feel like this is relatively simple but my brain is just out of gas and I don't know where to start. I'd appreciate any push in the right direction!
SQL Fiddle: http://sqlfiddle.com/#!9/44ae09/1