SQL LEFT JOIN

All rows from the left table.

✍️ 3 exercises + code challenge in this lesson

LEFT JOIN returns every row from the left table, and the matching rows from the right table. When there is no match, the right side is NULL.

This is perfect for questions like "which customers have never ordered?": left join, then keep rows where the right side is NULL.

Key Takeaways: SQL LEFT JOIN

Mastering SQL LEFT JOIN helps you write clean and reliable SQL code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

SQL LEFT JOIN Code Example

SQL
SELECT c.CustomerName, o.OrderID
FROM Customers c
LEFT JOIN Orders o ON o.CustomerID = c.CustomerID
ORDER BY c.CustomerName;

-- Customers with no orders at all
SELECT c.CustomerName
FROM Customers c
LEFT JOIN Orders o ON o.CustomerID = c.CustomerID
WHERE o.OrderID IS NULL;
Free sign-in required · Google login available

SQL LEFT JOIN Practice Exercises

Check what you learned in “SQL LEFT JOIN”.

/ 3 solved
Fill in the blank

Keep all customers, even without orders.

SELECT * FROM Customers c  Orders o ON o.CustomerID = c.CustomerID;
✓ Correct! Not quite. Try again.
Multiple choice

In a LEFT JOIN, what do the right-side columns contain when there is no match?

✓ Correct! Not quite. Try again.
Code challenge

Select the CustomerName of customers who have never placed an order, sorted by name.

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services