Reputation: 43
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
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