Course contentsShow
← Data Science
Lesson 953 of 2,14524. SQL JoinsFree lesson

Join Conditions: ON vs USING

When to use ON clauses versus USING clauses and the implications of each.

Join Conditions: ON vs USING

You'll learn: The two ways to specify join conditions and when each is most appropriate.

What's the Difference?

When joining tables, you've been using the ON clause to specify how rows match. SQL also offers a USING clause as a shortcut when the join columns have identical names in both tables.

Think of it like giving directions: ON lets you say "turn at the corner of Main and Elm," while USING says "turn at Main" when both streets are called Main.

ON Clause: Full Control

The ON clause explicitly states the matching condition, even when column names differ:

SELECT *
FROM orders o
INNER JOIN customers c ON o.customer_id = c.id;

You have complete flexibility here—different column names, complex conditions, multiple criteria.

USING Clause: Clean and Concise

When join columns share the exact same name, USING simplifies syntax:

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

This assumes both tables have a column named customer_id. The result has a subtle but important difference: the joined column appears once in the output, not twice.

Key Implications

  • USING only works when column names match exactly
  • USING produces cleaner output with no duplicate columns
  • ON is required for complex conditions (inequalities, multiple different columns)
  • USING can accept multiple columns: USING (col1, col2)
  • ON works everywhere; USING is syntactic sugar for the common case

Key Takeaway: Use USING for cleaner syntax when join columns share identical names; use ON for everything else or when you need explicit control over the join condition.