SQL LESSON 14 OF 32

LEFT JOIN: keep every customer

LEFT JOIN keeps every row on the left, even without a match. Missing right-side values become NULL. A right-table filter in WHERE can remove unmatched rows; put it in ON when you need to preserve them.

हिन्दी में समझें

LEFT JOIN बाईं तरफ की सभी पंक्तियाँ रखता है। मेल न होने पर दाईं ओर NULL आता है। दाईं टेबल का WHERE फ़िल्टर बिना मेल वाली पंक्तियाँ हटा सकता है।

अभ्यास: बिना order वाले ग्राहक का name, customer id क्रम में दिखाएँ।

Hinglish mein samjhein

LEFT JOIN left side ki saari rows rakhta hai. Match na mile to right values NULL. Right-table WHERE filter unmatched rows hata sakta hai; preserve karne ko ON mein filter do.

Practice: Jinke orders nahi hain unke name customer id sorted dikhao.

A small SQL example

SELECT c.name, o.id FROM customers c LEFT JOIN orders o ON c.id=o.customer_id ORDER BY c.id,o.id;

Examples use the fictional shop database bundled with the SQL playground: customers, products, orders, order_items and employees. The engine is SQLite; other SQL dialects may differ.

Try this example in the SQL playground →

Practise this idea

Find names of customers with no orders, ordered by customer id.

Check answer & explanation
SELECT c.name FROM customers c LEFT JOIN orders o ON c.id=o.customer_id WHERE o.id IS NULL ORDER BY c.id;

LEFT JOIN preserves every customer. A missing order match produces NULL in o.id, which identifies customers with no orders.

Stuck in the course? Choose Check answer for either the challenge or quiz. Read the explanation and continue to the next lesson at your own pace.

Check your understanding

An unmatched right-side value becomes…

  1. NULL
  2. 0
  3. An empty table
Check the quiz answer

NULL

LEFT JOIN keeps every row on the left, even without a match. Missing right-side values become NULL. A right-table filter in WHERE can remove unmatched rows; put it in ON when you need to preserve them.

References & corrections

Use the official SQLite documentation for full language rules. Read how these lessons are made and checked. Found a mistake? Report it to Excel Keys with this lesson URL and a reproducible example.

FROM LEARNING TO BUSINESS RESULTS

Need a dashboard for your team?

Excel Keys designs custom Excel and HTML dashboards around your own KPIs and Excel files. They run offline in the browser, so your data stays on your computer.