← PostgreSQL learning pathPostgreSQL · Module 4 of 10
Joins and relationships
Combine related tables with foreign keys and joins.
📖 Key ideas
- FOREIGN KEY links rows: orders.user_id REFERENCES users(id).
- INNER JOIN returns matching rows in both tables.
- LEFT JOIN keeps all left rows even without matches.
- Many-to-many uses a junction table.
- 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