CodeBlanks Logo Icon CodeBlanks

Summary - LEFT and RIGHT JOIN

Write a missing-record report with LEFT JOIN.

Summary - LEFT and RIGHT JOIN

LEFT JOIN keeps all rows of the left table, RIGHT JOIN keeps all rows of the right table. The unmatched side becomes NULL.

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

Summary left join.

c.name, o.id is selected from customers c. orders o is joined on o.customer_id = c.id, keeping every row of the left table.

Practice Summary - LEFT and RIGHT JOIN

Summary: LEFT JOIN customers with orders.

Starter code

query.sql
-- summary left join
SELECT c.name, o.id
FROM customers c

Sample solution

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

Expected output

name    id
Ayşe    1
Fatma   NULL

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What happens to the unmatched side?

  • It is deleted
  • An empty string
  • NULL Correct answer
  • An error

Explanation: The unmatched side comes as NULL.

2 Summary - LEFT and RIGHT JOIN: match the terms

Term Meaning
LEFT JOIN all left
RIGHT JOIN all right
NULL empty
COALESCE default

All lessons in Intermediate