I need some help with merging of overlapping intervals.
I have this table:
id start end 1 15:30:00 16:20:00 2 10:00:00 13:00:00 3 15:00:00 16:09:00 4 11:00:00 14:00:00 5 16:20:00 16:30:00
SQL:
CREATE TABLE `intervals` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`start` time NOT NULL,
`end` time NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO `intervals` (`start`, `end`) VALUES
('15:30:00', '16:20:00'),
('10:00:00', '13:00:00'),
('15:00:00', '16:09:00'),
('11:00:00', '14:00:00'),
('16:20:00', '16:30:00');
And I want output like this:
id start end 2 10:00:00 14:00:00 3 15:00:00 16:30:00
Only the start and end times matter; the ID column can basically be ignored.
There is similar implementation by PHP https://stackoverflow.com/a/4347215/1085872 (until step 2) but I need to do achieve the merge with only MySQL.