Part 05 / Topic 8 of 9
USING and NATURAL JOIN
When both sides name the key identically, USING shortens the ON — and collapses the pair into one output column:
SELECT o.order_id, c.first_name
FROM orders AS o
JOIN customers AS c USING (customer_id)
ORDER BY o.order_id
LIMIT 3;
order_id | first_name
----------+------------
1 | Asha
2 | Ravi
3 | Asha
(3 rows)
USING (customer_id) is fine and common. Its tempting big brother is not: NATURAL JOIN joins on every column name the tables share — whatever those happen to be today. Add a created_at column to both tables next year and the join condition silently changes, producing garbage with no error. Say what you join on; ON and USING both do.
🧪 Quick quiz — answer from memory, then check.
- What is the practical difference between
ON a.id = b.idandUSING (id)? - Why is NATURAL JOIN risky in production code?
Show the answers
- Same pairing; USING is shorter and outputs a single
idcolumn instead of two. - It joins on every same-named column — adding a column to both tables silently changes the join condition.
Done here? The practice set for Part 5 — 8 exercises with solutions — is on the part page.