Splitting things up
create table flights (
flight_id integer unique,
flight_number integer,
departure_time datetime,
seats integer,
max_weight number
);
create table passengers (
passenger_id integer unique,
last_name string,
first_names string,
weight_in_lbs number
);
create table reservations (
flight_id not null references flights,
passenger_id not null references passengers,
credit_card string,
time_placed datetime,
unique(flight_id,passenger_id)
);
-- JOIN, the Cartesian product
select *
from flights, passengers, reservations;
select *
from flights, passengers, reservations
where flights.flight_id = reservations.flight_id
and passengers.passenger_id = reservations.passenger_id;
-- passenger list for one particular flight
select last_name, first_names
from flights, passengers, reservations
where flights.flight_id = reservations.flight_id
and passengers.passenger_id = reservations.passenger_id
and flight_id = 10234;
Note that we don't tell the database which table to scan first.