mysql - Room Booking Query -
i have problem in writing sql availables rooms tables.
my tables structures given below.
table booking id | start_date | end_date table bookingroom (intermediate table) id | booking_id |room_id
a room can linked many bookings , booking can contain many rooms
table room contains id room
i have tried there probleme if room linked 2 differents bookings in separate dates comparaison maked first booking id
select distinct r.id room r ,booking b,bookingroom br r.id = br.id_room , b.id = br.id_booking , ( b.end_date < '05/14/2013' or b.start_date > '05/15/2013' )
can me write sql available rooms between checkin , checkout date.
if want list of rooms available entire range of desired dates, following might work:
select room.id room room.id not in ( select roomid bookingroom join booking on booking.id = bookingroom.bookingid booking.startdate <= 'desiredenddate' , booking.enddate >= 'desiredstartdate' ) order room.id
so, using original example, might get:
select room.id room room.id not in ( select roomid bookingroom join booking on booking.id = bookingroom.bookingid booking.startdate <= '2013-05-15' , booking.enddate >= '2013-05-14' ) order room.id
Comments
Post a Comment