Suppose I had 3 tables
- Passenger (Id [pk], name)
- Airplane (registration [pk], num_seats)
- Booking (Id, passenger_id [fk → Passenger ID], airplane_registration [fk → Airplane.registration])
The reservation table will be the connection point here, since there are many different relationships between the Passenger and Booking tables.
How can I select all the details related to a specific reservation identifier (for example, "abcde")?
Is it correct:
SELECT Passenger.name, Airplane.num_seats, Booking.Id FROM Booking JOIN Passenger ON Passenger.Id = Booking.passenger_Id JOIN Airplane ON Booking.airplane_registration = Airplane.registration WHERE Booking.Id = 'abcde';
Is this right to do? In addition, if I wanted to select all the orders and their details, would I do the same? (Without a where clause)?
I was looking to find out if this was correct for the test when MySQL went down to my machine.
source share