Ralph Villasoto
Ralph Villasoto

Reputation: 43

Building a Hotel Reservation

can anyone help me on how to get the available rooms from table1 to table2

here is the columns on my table1:

| id | roomTitle | description | maxOccupants | rate |

here is the column on my table2:

| id | arriveDate | departureDate | roomId | guestName |

my sql is (this will check if the users date request is available):

SELECT *
FROM table2
WHERE departureDate <= '...' OR arriveDate >= '...';

how to gather all available rooms from the table1 using the results on table2?

please correct me if I am wrong, i'm just a student trying to learn more, Thanks!

Upvotes: 0

Views: 149

Answers (2)

Neville Kuyt
Neville Kuyt

Reputation: 29619

If you're asking "show me which rooms are available on a given date", you need something like:

select *
from   table1
where id not in
  (select roomid 
   from table2
   where   departureDate <= '$arrivalDate' 
   or arriveDate >= '$departdate')

Upvotes: 1

Alan Kael Ball
Alan Kael Ball

Reputation: 680

You'll need to use a JOIN using tabel1 id and table2 roomid

Upvotes: 0

Related Questions