Multi-Table Joins

So far, all the queries that you've seen involve a single table. Most databases contain multiple tables and there are relationships between these tables. This sample database has an example:

movies=# \d rentals

            Table "rentals"
  Attribute  |     Type     | Modifier
-------------+--------------+----------
 tape_id     | character(8) | not null
 rental_date | date         | not null
 customer_id | integer      | not null

Here's a description of the rentals table from earlier in this chapter:

“When a customer comes in to rent a tape, we will add a row to the rentals table to record the transaction. There are three pieces of information that we need to record for each rental: the tape_id, the customer_id, and the date that the rental occurred. Notice that ...

Get PostgreSQL, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.