0

我有 2 张桌子,Facility 和 Reservation 桌子。

设施表包含,

  • 设施ID
  • 类型
  • 姓名
  • 可用性

预订表,

  • ID
  • 会员ID
  • 设施ID
  • 登记日期
  • 登记时间

这是我的查询,它只返回保留的详细信息。如何进行查询以返回那些未保留的设施详细信息?

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 & "')
4

1 回答 1

0

您可以使用 LEFT OUTER JOIN 和 IS NULL 仅返回 Reservation 表中没有记录的行。

以下查询将返回在 FacilityID、MemberID 和入住日期的 Reservation 表中不匹配的所有设施。如果您想查看他们是否有任何会员的预订和任何入住日期,您可以删除 MemberID 和入住日期部分

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
于 2013-03-10T04:10:31.183 回答