typestar

RIGHT and FULL OUTER JOIN in SQL

LEFT keeps the left side's rows. RIGHT and FULL keep the others.

SELECT
    c.name,
    o.id AS order_id
FROM orders AS o
RIGHT JOIN customers AS c
    ON c.id = o.customer_id;

SELECT
    p.sku,
    i.order_id
FROM products AS p
FULL OUTER JOIN order_items AS i
    ON i.sku = p.sku;

How it works

  1. RIGHT JOIN keeps unmatched rows from the right table.
  2. FULL OUTER JOIN keeps unmatched rows from both sides.
  3. SQLite has had all three since 3.39; before that you flipped the tables.

Keywords and builtins used here

The run, in numbers

Lines
13
Characters to type
195
Tokens
55
Three-star pace
85 tpm

At the three-star pace of 85 tokens a minute, this run takes about 39 seconds.

Type this snippet

Step 4 of 9 in Joins, step 12 of 22 in Joins & aggregation.

← Previous Next →