I have spent more than 14 hours trying to find a way to accomplish this but no luck!
I'm working on a booking system , I have 2 tables :
Rooms
---------
ID - ROOM_TYPE - NAME - ROOM_COUNT
1 1 single room 6
2 2 double room 4
3 3 studio 2
Booking
---------
ID - ROOM_TYPE - Customer_NAME - CHECK_IN - CHECK_OUT
1 3 John A 1-1-2013 4-1-2013
2 3 John B 2-1-2013 5-1-2013
3 2 John C 8-1-2013 9-1-2013
after the user put 2 dates to search for an available room , I make a query to display all type rooms that I have , I have 3 types (single/double/studio), each type has number of rooms available in the hotel (ex: the hotel has 6 single rooms by default)
I end up with this query to get all available type rooms
SELECT *
FROM rooms
where id NOT IN
( SELECT room_type FROM booking
WHERE "'.$check_in.'" <= check_out
AND "'.$check_out.'" >= check_in
)
I need to make another condition that WHERE count(room_type) from booking LESS than the value saved in ROOM_COUNT field in ROOMS table ..
depend on the table structures above , the hotel has just two studios and all aren't available in 4-1-2013 .. so, the query shouldn't display studio type room when somebody search in that date ..
I need something like count how many bookings for each room type then display the results ..
Thank you in advance