user3792136
user3792136

Reputation: 1

SQL Query: looking for null

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:

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

Answers (2)

Guest1
Guest1

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

SchmitzIT
SchmitzIT

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

Related Questions