Reputation: 1
The question is: You want to be the first to book and pick seats for a flight. Find the flight_num
and date of all flights for which there are no reservations.
From the following tables:
Flights
(flight_num, source_city, dest_city
)Departures
(flight_num, date, plane_type
)Passengers
(passenger_id, passenger_name, passenger_address
)Bookings
(passenger_id, flight_num, date, seat_number
)My answer was:
SELECT D.flight_num, D.date
FROM DEPARTURES D, BOOKINGS B
WHERE B.passenger_id = NULL
I know this is wrong, but can anyone tell me why? What is the answer to this?
Upvotes: 0
Views: 133
Reputation: 1
This might work?
SELECT D.flight_num, D.date
FROM Departures D LEFT OUTER JOIN Bookings B
WHERE B.passenger_id IS NULL
Upvotes: 0
Reputation: 9552
This might be better:
SELECT D.flight_num, D.date
FROM DEPARTURES D JOIN BOOKINGS B ON D.flight_num = B.flight_num
WHERE B.passenger_id IS NULL
I'm not sure if it would be possible to book, but not reserve a seat number. If it is, then you need to change the WHERE clause for that.
Upvotes: 1