</>
Skip to content
SQL lessons (26/54)

SQL — Left Join

Basic LEFT JOIN

SELECT u.name, o.total
FROM users u
LEFT JOIN orders o ON u.id = o.user_id;

All users with orders

-- Users without orders will have NULL
SELECT u.name, o.total
FROM users u
LEFT JOIN orders o ON u.id = o.user_id;

Find users without orders

SELECT u.name
FROM users u
LEFT JOIN orders o ON u.id = o.user_id
WHERE o.id IS NULL;

LEFT JOIN with aggregate

SELECT u.name, COUNT(o.id) AS order_count
FROM users u
LEFT JOIN orders o ON u.id = o.user_id
GROUP BY u.name;

Multiple LEFT JOINs

SELECT u.name, o.total, p.name AS product
FROM users u
LEFT JOIN orders o ON u.id = o.user_id
LEFT JOIN products p ON o.product_id = p.id;

Mini Practice

  1. Perform LEFT JOIN
  2. Find records without matches
  3. Use with aggregate functions
  4. Chain multiple LEFT JOINs

Up Next

Continue with Right Join - Right join operations.

Related Topics

Frequently Asked Questions about Left Join

What is Left Join in SQL?

Left Join is a fundamental concept in SQL. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Left Join?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Left Join.

Why is Left Join important in SQL?

Left Join is essential for SQL development. Understanding this concept will help you write better code and solve real-world problems more effectively.