Database Reference
In-Depth Information
sheet with a list of orders of birds, and you wanted to type on your screen a list of bird
with their names, along with the family and order to which each belonged, you would do
the same thing with your fingers, pointing from keywords on one sheet to the keyword on
the other. It's really intuitive when you think about it.
Let's look now at the columns we have selected. We are selecting the
common_name
and
scientific_name
columns from the
birds
table. Again, I've added indenting and
put these columns on separate lines for clarity. Because all three tables have columns
named
scientific_name
, we must include the table name for each column (e.g.,
birds.scientific_name
) to eliminate ambiguity. I've added also an
AS
clause to
each column selected to give the results table nicer column headings. The
AS
clausehas
nothing to do with the tables on the server; it affects only what you see in your output. So
you can choose the column headings in the results through the string you put after the
AS
keyword.
Let's take a moment to consider the results. Although we entered the scientific name of
each family and order referenced here only once, MySQL can pull them together easily by
way of the
family_id
and
order_id
columns in the tables. That's economical and
very cool.
As I said before, the SQL statement I've just shown is much more complicated than any-
thing we've looked at before. Don't worry about taking in too much of it, though. We'll
what we're doing. The kind of inquiries we can make of data this way is so much better
than one big table with columns for everything. For each shore bird, we had to enter only
103 for the
family_id
column and didn't have to type the scientific name for the fam-
ily, or enter the scientific name of the order for each bird. We don't have to worry so much
about typos. This leverages your time and dataefficiently.