Thus far, our queries have only accessed one table at a time.
Queries can access multiple tables at once, or access the same
table in such a way that multiple rows of the table are being
processed at the same time. A query that accesses multiple rows
of the same or different tables at one time is called a join
query. As an example, say you wish to list all the weather
records together with the location of the associated city. To do
that, we need to compare the city column of each row of the
weather table with the name column of all rows in the cities
table, and select the pairs of rows where these values match.
Note: This is only a conceptual model. The join is usually
performed in a more efficient manner than actually comparing
each possible pair of rows, but this is invisible to the user.
This would be accomplished by the following query: SELECT * FROM
weather, cities WHERE city = name; city | temp_lo | temp_hi |
prcp | date | name | location ---------------+---------+--------
-+------+------------+---------