For a booking system I have a table with rooms, arrival and departure.
Example data:
id | room | arrival | departure
---+------+------------+-----
Here is a query that will show the NOT-FREE rooms for a date span:
select room from bookings where
(arrival<'2011-03-12' and departure>='2011-03-12') -- overlap at the end
OR (arrival<='2011-03-10' and departure>'2011-03-10') -- overlap at the start
OR (arrival>='2011-03-10' and departure<='2011-03-12') -- complete overlap
You can use this with
select roomnumber from rooms where roomnumber not in (... as above ...)
to find the FREE rooms