Course map
Stage 1: Foundation
Stage 2: Intermediate
Stage 3: Advanced
Stage 4: Performance & internals
Stage 5: Specialization

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.

  1. What is the practical difference between ON a.id = b.id and USING (id)?
  2. Why is NATURAL JOIN risky in production code?
Show the answers
  1. Same pairing; USING is shorter and outputs a single id column instead of two.
  2. 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.

Search the guide