如何改进我的查询,以便只选择那些在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
答案 0 :(得分:2)
您可以在WHERE子句中使用Not In,如下所示。如果它在子查询中找不到座位,那么它将在结果中列出seat_no。
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
)