SQL Exercises

PostgreSQL: Intermediate SQL LEFT JOIN Exercises

0 Exercises
~0 min

This guide is specifically for PostgreSQL syntax.

Intermediate-level SQL LEFT JOIN practice exercises with solutions.

Exercise 1

Question: List all employees and their departments, including employees without a department.

SELECT e.name AS employee, d.name AS department FROM employees e LEFT JOIN departments d ON e.department_id = d.id;

LEFT JOIN returns all rows from the left table and matching rows from the right. Unmatched right-side rows show as NULL.

Exercise 2

Question: Find customers who have never placed an order.

SELECT c.name FROM customers c LEFT JOIN orders o ON c.id = o.customer_id WHERE o.id IS NULL;

This pattern (LEFT JOIN + WHERE IS NULL) finds rows in the left table that have no match in the right table.


PostgreSQL-Specific Notes

This page covers PostgreSQL syntax. Other databases may have different syntax for similar operations.

Related Content

From Our Blog

Ready for more practice?

Join SQL Mastery and get access to interactive exercises, quizzes, and more.