Entry
How do I do a JOIN statement?
How do I handle join statements where the same column name is in multiple tables?
Jan 23rd, 2000 19:05
Nathan Wallace, Ville Mattila, Richard Lynch
A JOIN defines the relationship between two (or more!) tables. The
basic things you need to supply are the two tables and a "where " clause
defining how the two tables relate.
So, if we have two tables:
FLIGHTS:
Fields: Airline, Flight Number
AIRLINES:
Fields: Code, Name
Assuming "Name" in AIRLINES is the same as "Airline" in FLIGHTS:
select ...
from FLIGHTS, AIRLINES
where FLIGHTS.Airline = AIRLINES.name
Now, for the ... part, you put the columns you want. Sometimes, though,
you can have *TWO* columns in different tables with the same name. (You
don't here, but you could have.) When you need to "fully qualifiy" a
column, you add the table and a period in front, just like in the where
clause above. So I would write this as:
select AIRLINES.Code, AIRLINES.Name, 'FLIGHTS.Flight Number' ...