Interview's MateSQL Learning
Interview's Mate

SQL Learning

Foundations → production SQL

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
SQL topics
Lesson 51/ 160
03. Joins & Relational Querying

NATURAL JOIN & USING Clause (and Why to Avoid NATURAL JOIN)

Use USING for shared key names and avoid brittle NATURAL JOIN surprises.

IntermediateUSING · NATURAL JOIN Risks3 quiz questions
Practice SQL
In plain wordsDiagramExamples & theoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

USING joins on a column with the same name in both tables. NATURAL JOIN guesses which columns to join on, and can guess wrong.

Think of it like…

USING is saying "match people by their employee number". NATURAL JOIN is saying "match people on everything your two lists have in common": fine until both lists gain a "date added" column and nobody matches any more.

Where you’ve seen it

A schema where every foreign key repeats its parent's key name (orders.customer_id, customers.customer_id) can write SELECT customer_id, name, amount FROM orders JOIN customers USING (customer_id);. With NATURAL JOIN, adding updated_at to both tables would make the join require equal update timestamps too.

Words you’ll hear

USING (cols)
Join on the listed columns, which must have the same name in both tables.
Merged column
With USING, the join column appears once in the output.
NATURAL JOIN
Joins on all columns with matching names, chosen implicitly.
Support
PostgreSQL, MySQL, Oracle and SQLite support both; SQL Server supports neither.

Visual diagram

Loading interactive diagram

Theory & example queries

JOIN … USING

USING (a, b) means ON left.a = right.a AND left.b = right.b, and the output has a single a and b column rather than one from each table. You can refer to the merged column without a table prefix, which keeps SELECT lists short. With outer joins, the merged column takes whichever side's value isn't NULL.

It only works when the key has the same name in both tables, which favours naming foreign keys after the parent's key (customer_id in both customers and orders) rather than a generic id. If the parent's key is just id, you need ON.

Joining three tables with USINGQuery example
1Input dataStart from the source rows or state that the statement sees.
customers
3 rows
customers sample rows
idnameemailcity
1Mayamaya@example.comPune
2Raviravi@example.comDelhi
3Noornoor@example.comMumbai
orders
3 rows
orders sample rows
idcustomer_idstatusamountcoupon_code
1011paid249NULL
1022paid120WELCOME10
1031shipped89.5NULL
order_items
3 rows
order_items sample rows
idorder_idproduct_idqtyprice
110142249.5
2101841150
310242149.5
2QuerySwitch dialects, then select a line or execution step to trace it.
query.sql
1SELECT2  order_id,3  customer_id,4  product_id,5  qty6FROM7  orders8  JOIN order_items USING (order_id)9  JOIN customers USING (customer_id);
Logical execution order
Native / baseline

PostgreSQL is the lesson baseline unless noted otherwise.

Line 1 · Project and calculate

Calculate the selected expressions and return the requested output columns.

1/9
3OutputInspect the representative rows, affected-row count, plan, or command status.
Representative joined rows3 sample rows
Representative joined rows
order_idcustomer_idproduct_idqty
90017412
90017561
90028414

Note: Sample data assumes both orders have matching customers and each selected order item satisfies the USING joins.

4ExplanationConnect the result back to the SQL rule and the edge case it demonstrates.

Key takeaway: USING = ON with matching names, output column shown once.

Why NATURAL JOIN is risky

NATURAL JOIN decides the join columns from the current table definitions. Adding a column with a common name (status, created_at, updated_at, name) to both tables silently adds it to the join condition, and the query keeps running but returns far fewer rows. If the tables share no column names, it becomes a cross join.

Because the condition isn't written anywhere, readers can't tell from the query what it joins on. Most style guides ban NATURAL JOIN in production code. SQL Server supports neither NATURAL JOIN nor USING, so ON is also the most portable choice.

The silent changeQuery example
1Input dataStart from the source rows or state that the statement sees.
customers
3 rows
customers sample rows
idnameemailcity
1Mayamaya@example.comPune
2Raviravi@example.comDelhi
3Noornoor@example.comMumbai
orders
3 rows
orders sample rows
idcustomer_idstatusamountcoupon_code
1011paid249NULL
1022paid120WELCOME10
1031shipped89.5NULL
2QuerySwitch dialects, then select a line or execution step to trace it.
query.sql
1SELECT2  *3FROM4  orders5  NATURAL JOIN customers;
Logical execution order
Native / baseline

PostgreSQL is the lesson baseline unless noted otherwise.

Line 1 · Project and calculate

Calculate the selected expressions and return the requested output columns.

1/5
3OutputInspect the representative rows, affected-row count, plan, or command status.
One possible post-migration match1 sample row
One possible post-migration match
customer_idupdated_atorder_idamountname
72026-11-19 10:15:009001249.5Asha

Note: This assumes the only surviving NATURAL JOIN keys are customer_id and updated_at and exactly one order/customer pair shares the timestamp. The result can be empty for the same reason.

4ExplanationConnect the result back to the SQL rule and the edge case it demonstrates.

worked when the only shared column was customer_id. After a migration adds updated_at to both tables, it only returns pairs updated at exactly the same moment, which is almost none.

Key takeaway: Avoid NATURAL JOIN; use USING or ON.

Interactive walkthrough

How it works, step by step

Follow one practical SQL workflow from start to finish. Select any step or play through the flow.

Progress1/4
Step 1Schema

Check the key names

See whether the join columns have the same name in both tables (customer_id and customer_id).

Focus at this step

orders.customer_id · customers.customer_id

What to watch at this step
Same name
USING possible
Tip: use ← → to move between steps

When to use it & trade-offs

What it is

JOIN … USING (col) is shorthand for joining on columns that have the same name in both tables: orders JOIN customers USING (customer_id). The result shows that column once instead of twice. NATURAL JOIN goes further and joins on *every* column name the two tables share, automatically, which is why it's widely considered dangerous.

Why it matters: USING makes joins on consistently named keys shorter and clearer. NATURAL JOIN can change silently when someone adds a column with a common name like created_at or status to both tables, turning a working report into one that returns almost nothing. Interviewers ask about it to see whether you know that risk.

When to reach for it

  • USING in schemas with consistent key names
  • ON for everything else and for portable SQL
  • Explaining why NATURAL JOIN is discouraged

When to avoid or be careful

  • NATURAL JOIN in production queries
  • USING when the code must also run on SQL Server
  • Generic id primary keys if you want to use USING

ON vs USING vs NATURAL JOIN

ON
Best for: Every join, especially with different column names or extra conditions

Strengths: Explicit, flexible and supported everywhere.

Watch out: Slightly longer; join columns appear twice in SELECT *.

USING
Best for: Joins on keys with identical names

Strengths: Concise; join column appears once.

Watch out: Not in SQL Server; needs consistent naming.

NATURAL JOIN
Best for: Quick ad-hoc exploration at most

Strengths: Shortest possible syntax.

Watch out: Join columns are implicit and change when the schema changes.

Interview signals & numbers to know

When this topic comes up

  • “What does NATURAL JOIN do?”
  • “A report broke after a migration added a column”
  • JOIN … USING in existing code
  • SQL style guides
  • Ambiguous column errors

Benchmarks & rules of thumb

1 -
copy of each USING column in the output
All shared names -
used by NATURAL JOIN
0 -
support for USING in SQL Server

Common mistakes & follow-ups

Common interview mistakes

  • Using NATURAL JOIN and having it silently include updated_at after a schema change.
  • Trying USING (id) when the foreign key is called customer_id.
  • Porting PostgreSQL code with USING to SQL Server and getting syntax errors.

Likely interviewer follow-ups

  • What's the difference between JOIN … USING and NATURAL JOIN?
  • Why do many teams forbid NATURAL JOIN?
  • What happens to the join column in the output when you use USING?
Interview tip: Explain USING as "ON for same-named columns", then give the updated_at story for NATURAL JOIN. The concrete failure is what convinces interviewers you understand the risk.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply NATURAL JOIN & USING Clause (and Why to Avoid NATURAL JOIN) with hands-on SQL practice and interview Q&A.

Open SQL Practice →SQL interview Q&A
Previous topic
Non-Equi Joins (Joining on Ranges, Dates & Inequalities)
Next topic
Filtering in ON Clause vs WHERE Clause in Outer Joins