任何人都可以帮助我如何从table1到table2获取可用的房间
这是我桌子上的列:
| id | roomTitle | description | maxOccupants | rate |
这是我桌子上的一栏:
| id | arriveDate | departureDate | roomId | guestName |
我的sql是(这将检查用户日期请求是否可用):
SELECT *
FROM table2
WHERE departureDate <= '...' OR arriveDate >= '...';
如何使用table2上的结果从table1收集所有可用房间?
如果我错了,请纠正我,我只是一名学生想要了解更多,谢谢!答案 0 :(得分:1)
如果您问“告诉我哪个房间在指定日期可用”,您需要以下内容:
select *
from table1
where id not in
(select roomid
from table2
where departureDate <= '$arrivalDate'
or arriveDate >= '$departdate')
答案 1 :(得分:0)
您需要使用JOIN
使用tabel1 id和table2 roomid