MySQL
SQL Joins
USING Clause
ON Clause
Database Optimization

USING Keyword vs ON clause - MYSQL

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

In MySQL joins, USING and ON both express join conditions, but they are not interchangeable in every case. USING is a shorthand for equality joins on columns that have the same name in both tables. ON is the general form and supports arbitrary join logic. The most important practical difference is not only syntax. It is also how the output columns are shaped.

Use USING for Same-Named Equality Joins

When both tables contain the same join column name and the join condition is simple equality, USING is concise.

sql
SELECT customer_id, customer_name, order_date
FROM customers
JOIN orders USING (customer_id);

This is roughly equivalent to:

sql
SELECT customers.customer_id, customer_name, order_date
FROM customers
JOIN orders ON customers.customer_id = orders.customer_id;

The benefit of USING is readability when the join is straightforward.

ON Is More Flexible

Use ON when:

  • the column names differ
  • the condition involves more than equality
  • you need multiple predicates
  • you want the join logic to stay fully explicit
sql
1SELECT u.id, p.display_name
2FROM users AS u
3JOIN profiles AS p
4  ON u.id = p.user_id
5 AND p.is_active = 1;

You cannot express this cleanly with USING because the column names differ and there is an extra predicate.

Output Columns Behave Differently

This is the detail many developers miss. With USING, MySQL returns one merged join column in the result set rather than separate copies from each table.

For example:

sql
SELECT *
FROM customers
JOIN orders USING (customer_id);

The result contains a single customer_id column.

With ON:

sql
SELECT *
FROM customers
JOIN orders ON customers.customer_id = orders.customer_id;

the output can contain both table versions of the join column when you use SELECT *. That can affect client code, column naming, and query readability.

So the choice is partly semantic and partly about how you want the result set to look.

Prefer Explicitness in Complex Queries

In simple joins, USING is fine. In larger queries involving aliases, outer joins, or multiple conditions, ON is usually easier to maintain because every predicate is visible in one place.

That clarity becomes especially important when conditions are added later. A join that starts as a one-column equality often grows into something more specific, and ON scales better as the query evolves.

Avoid Confusing USING With NATURAL JOIN

USING still requires you to name the join columns explicitly. NATURAL JOIN automatically joins on all same-named columns, which is usually too implicit for production SQL. If the schema changes, NATURAL JOIN behavior can change unexpectedly.

USING is safer because it keeps the join columns deliberate.

Common Pitfalls

  • Assuming USING is just style sugar and forgetting that it changes the projected join columns.
  • Trying to use USING when the join columns have different names.
  • Hiding complex join logic inside filters elsewhere instead of keeping it visible with ON.
  • Using SELECT * with ON and then being surprised by duplicate join columns in the result set.
  • Confusing USING with NATURAL JOIN, which is far more implicit and risky.

Summary

  • 'USING is a shorthand for equality joins on same-named columns.'
  • 'ON is the general-purpose join syntax and handles complex conditions.'
  • The result shape differs: USING merges the join column, while ON can expose both copies.
  • Prefer USING for short, obvious joins and ON for flexibility and long-term maintainability.
  • Be deliberate about result-set shape, especially when queries use SELECT *.

Course illustration
Course illustration

All Rights Reserved.