MySQL - Finding time overlaps
Posted
by Jude
on Stack Overflow
See other posts from Stack Overflow
or by Jude
Published on 2010-04-28T07:02:27Z
Indexed on
2010/04/28
7:13 UTC
Read the original article
Hit count: 335
Hi, I have 2 tables in the database with the following attributes:
Booking
=======
booking_id
booking_start
booking_end
resource_booked
===============
booking_id
resource_id
The second table is an associative entity between "Booking" and "Resource" (i.e., 1 booking can contain many resources). Attributes booking_start and booking_end are timestamps with date and time in it.
May I know how I might be able to find out for each resource_id (resource_booked) if the date/time overlaps or clashes with other bookings of similar resource_id?
I was doodling the answer on paper, pictorially, to see if it might help me visualize how I could solve this and I got this:
- Joining the 2 tables (Booking, Booked_resource) into one table with the 4 attributes needed.
- Follow the answer suggested here : http://stackoverflow.com/questions/689458/find-overlapping-date-time-rows-within-one-table
I did step 1 but step 2 is leaving me baffled!
I would really appreciate any help on this! Thanks!
© Stack Overflow or respective owner