← PostgreSQL learning path
PostgreSQL · Module 4 of 10

Joins and relationships

Combine related tables with foreign keys and joins.

📖 Key ideas

  1. FOREIGN KEY links rows: orders.user_id REFERENCES users(id).
  2. INNER JOIN returns matching rows in both tables.
  3. LEFT JOIN keeps all left rows even without matches.
  4. Many-to-many uses a junction table.
  5. ON DELETE CASCADE removes children with parents.
💡 Real-life example: A join is matching students to their marksheets using roll numbers.
Foreign keyColumn referencing another table
INNER JOINOnly matching rows
LEFT JOINAll left rows plus matches
Junction tableTable linking many-to-many