Using LEFT JOIN and RIGHT JOIN in PostgreSQL
📖 Scenario: You work for a small bookstore that keeps two tables: one for authors and one for books. Some authors may not have published books yet, and some books may not have a listed author.
🎯 Goal: Build SQL queries using LEFT JOIN and RIGHT JOIN to combine the authors and books tables. This will help you see all authors with their books, and all books with their authors, even if some data is missing.
📋 What You'll Learn
Create a table called
authors with columns author_id (integer) and author_name (text).Create a table called
books with columns book_id (integer), title (text), and author_id (integer).Insert specific data into both tables as given.
Write a
LEFT JOIN query to list all authors and their books (if any).Write a
RIGHT JOIN query to list all books and their authors (if any).💡 Why This Matters
🌍 Real World
Bookstores and libraries often keep separate tables for authors and books. Using LEFT and RIGHT JOINs helps show complete lists even when some data is missing.
💼 Career
Understanding JOINs is essential for database querying jobs, data analysis, and backend development where combining related data is common.
Progress0 / 4 steps