0

如何改进我的查询,以便只选择那些尚未在 Pasenger_Detail 表中选择的记录。

Private Sub BR_ID_LostFocus()
   Dim s As String

   s = "Select seat_no.seat_no" & _
       " FROM Seat_No" & _
       " Where seat_no.seat_no <=  " & _
       " (select br_info.Seats_Reserved from br_info where "  & _
       " Br_info.br_id=forms!pasenger_detail!br_id);"

  Me.Seat_No.RowSource = s
  Me.Seat_No.Requery
End Sub
4

1 回答 1

2

您可以在 WHERE 子句中使用 Not In,如下所示。如果在子查询中没有找到座位,那么它会在结果中列出座位号。

SELECT Seat_No.seat_no 
FROM Seat_No 
WHERE Seat_No.seat_no <= 
(
  SELECT br_info.Seats_Reserved 
  FROM br_info 
  WHERE br_info.br_id = forms!pasenger_detail!br_id
) 
AND Seat_No.seat_no NOT IN 
(
  SELECT pasenger_detail.seat_no 
  FROM pasenger_detail
)
于 2013-09-23T12:37:37.163 回答