我有2个表,Facility和Reservation表。
设施表包含,
预订表,
这是我的查询,它只返回保留的详细信息。如何使查询返回那些未预留的设施详细信息?
SELECT Facility.[Facility Name], Facility.[Facility Type]
FROM Facility INNER JOIN Reservation on Facility.FacilityID = Reservation.FacilityID
WHERE Reservation.FacilityID = (
SELECT FacilityID
FROM Reservation
WHERE MemberID = '" & txtMemberID.Text & "'
AND [Check-in date] ='" & lstDate.SelectedItem.ToString & "')
答案 0 :(得分:0)
您可以使用LEFT OUTER JOIN和IS NULL仅返回Reservation表中没有记录的行。
以下查询将返回FacilityID,MemberID和Check-In日期的Reservation表中没有匹配项的所有工具。如果您想查看他们是否有任何会员的预订和任何入住日期,您可以删除会员ID和登记日期部分
SELECT Facility.[Facility Name], Facility.[Facility Type]
FROM Facility
LEFT OUTER JOIN Reservation on Facility.FacilityID = Reservation.FacilityID
AND MemberID = '" & txtMemberID.Text & "' // pull in based on certain member
AND [Check-in date] ='" & lstDate.SelectedItem.ToString & "') // pull in based on certain date
WHERE Reservation.ID IS NULL