liveBook · Manning

Multitable query

As explained in Learn SQL in a Month of Lunches

A multitable query is an SQL query that references more than one table to retrieve or filter data.

A multitable query references more than one table to retrieve or filter data. In practice, joins connect related rows so a condition in one table can identify values in another. section 17.1.4

Find titles by an author

To find prices for titles written by author 12, join title to titleauthor and filter on AuthorID. The titleauthor table connects the two entities in their many-to-many relationship. section 17.1.4

Common steps include:

  • Start with a SELECT query to inspect the rows that an update will affect. section 17.1.4
  • Join tables through matching keys, such as TitleID and AuthorID. section 17.1.4
  • Use a predicate to filter the desired rows, then place the update syntax according to the database product. section 17.1.4
SELECT title.Price
FROM title
INNER JOIN titleauthor
    ON title.TitleID = titleauthor.TitleID
INNER JOIN author
    ON titleauthor.AuthorID = author.AuthorID
WHERE author.AuthorID = 12;

Browse the complete joined SELECT query, with an equivalent abbreviated form using table aliases. section 17.1.4

How Learn SQL in a Month of Lunches covers it

How deep it goes
Explains joins, keys, predicates, aliases, and UPDATE placement, but stops short of comprehensive RDBMS syntax coverage.
Examples
Demonstrates selecting and updating title prices for author 12 through title, titleauthor, and author tables.
What it assumes
Assumes SQL predicates, filtering, table keys, and relationships, while reinforcing these through a concrete example.
What you can do after
Apply it via SQL joins to preview and update rows identified through related tables.
How it connects
Connects SQL queries with joins, predicates, SELECT statements, UPDATE statements, and many-to-many relationships.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn SQL in a Month of Lunches. The section links point to the parts of the book it draws on.