Memra

INNER JOIN: combining tables

◈ 2 cards

Follow a foreign key to another table.

Connect related tables

books.author_id points at authors.id — a foreign key. A JOIN follows that link so you can show columns from both tables together:

SELECT books.title, authors.name
FROM books
JOIN authors ON books.author_id = authors.id;

The ON clause says how rows match up. A plain JOIN (a.k.a. INNER JOIN) keeps only rows that match on both sides. Aliases keep it short — FROM books b JOIN authors a ON b.author_id = a.id.

FKauthorsid intname textcountry textbooksid inttitle textauthor_id intgenre textprice numeric
The join condition IS the arrow: books.author_id = authors.id. A solid underline marks a primary key, a dashed one a foreign key — keep this open while you write the query.
NORMAL ~/memra/learn/postgresql/inner-join utf-8 LF