I found an answer here on SO about the common problem of finding the available time slots in a database. The query works like a charm but it starts failing if I add a new event which starts before the alredy added events. In that case the order of the output is wrong. There is alredy a sqlFiddle example in the answer, I just added in the schema a new line:
insert into bookingEvents values (null, '2013-05-12 05:11:00', 15);
As you can see the date of the event is before the last previously inserted event's date (they're not anymore in order by timeBooked). Maybe I'm trying to put too much logic into a query, if it's like so then how could I handle this thing with PHP too?
EDIT
Probably I should first flatten the timestamps and then execute the query on the result. I found something to flatten the timestamps but I need help to merge the two queries and get something optimized for production