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
RIGHT JOINkeeps unmatched rows from the right table.FULL OUTER JOINkeeps unmatched rows from both sides.- SQLite has had all three since 3.39; before that you flipped the tables.
Keywords and builtins used here
ASFROMFULLJOINONOUTERRIGHTSELECTc
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.
Step 4 of 9 in Joins, step 12 of 22 in Joins & aggregation.