I have a table with records and a period of time for each record, like reservations for instance. So my records look like this:
Table-reservations id room datefrom dateto 1 'one' '2015-09-07' '2015-09-12' 2 'two' '2015-08-11' '2015-09-02' 3 'three' '2015-06-11' '2015-06-14' 4 'two' '2015-07-30' '2015-08-10' 5 'four' '2015-06-01' '2015-06-23' 6 'one' '2015-03-21' '2015-03-25' ... n 'nth' '2015-06-01' '2015-07-03' Also there is a table with rooms containing an ID, a roomnumber and a roomtype, like this:
Table-rooms idrooms room roomtype 1 'one' 'simple' 2 'two' 'simple' 3 'three' 'double' ... nx 'nth' 'simple' As you can see some rooms appear multiple times, but with different periods, because they are booked on various periods. What I need to obtain through SQL is a list of rooms that are available in a given period of time.
So something like(pseudocode):
Select room from table where there is no reservation on that room between 2015-08-13 and 2015-08-26 How can I do this?
So I will have a fromdate and a todate and I will have to use them in a query.
Can any of you guys give me some pointers please?
Right now I use the following sql to obtain a list of rooms that are available NOW
select * from rooms where idrooms not in ( select idroom from rezervations where ((date(now())<=dateto and date(now())>=datefrom)or(date(now())<=dateto and date(now())<=datefrom)) ) order by room
(integer:idroom, varchar():room, varchar():type)