0

how can improve my query so that only those records should be selected those are not selected yet in Pasenger_Detail table.

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
2
  • can you submit table definitions? Commented Sep 23, 2013 at 8:25
  • i added pic of relationship might be it help u. Commented Sep 23, 2013 at 16:08

1 Answer 1

2

You can use Not In in your WHERE clause like below. If it does not find the seat in the sub query then it will list seat_no in the results.

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
)
Sign up to request clarification or add additional context in comments.

8 Comments

boss i did it earlier and was working. but problem with this is shows those seat nos which are not being selected yet. but it show all fields entries from seat _no table, but i need only till those which meet my maximum seat_no criteria.
in short i need both thing, first which is already working in this query also one you suggested.
You lost me at hello. Your English is difficult for me to follow. Can you explain what is being stored in what table and how they relate to each other? We obviously need more information.
i tried to improve it in this way but it does not work. "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) NOT IN (select pasenger_detail.seat_no);"
That would not work. It is not a proper SQL statement. Maybe the following is what you are after: 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)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.