← Back to Glossary

USING clause

The USING clause specifies join columns by name when both tables share identically named columns, joining on equality and returning a single copy of each shared column.

Overview

The USING clause is shorthand for specifying join conditions when two tables share one or more identically named columns. Instead of writing out a full ON equality condition, USING (col) joins on that column directly:

Copy code

SELECT * FROM orders JOIN customers USING (customer_id); -- equivalent to: SELECT * FROM orders o JOIN customers c ON o.customer_id = c.customer_id;

USING vs ON: the key difference in output

The two forms aren't purely stylistic -- they behave differently in the result set. USING (customer_id) produces a single, unqualified customer_id column in the output. ON o.customer_id = c.customer_id keeps both orders.customer_id and customers.customer_id as separate columns, which then need explicit qualification (or exclusion) if selected with SELECT *, since both tables have a same-named column.

Multiple columns

USING can list multiple shared columns to join on all of them simultaneously:

Copy code

SELECT * FROM sales JOIN inventory USING (store_id, product_id);

USING vs NATURAL JOIN

USING requires you to explicitly name the join columns, while NATURAL JOIN infers them automatically from every column name the two tables happen to share. USING is the safer, more maintainable middle ground: it avoids repeating a fully-qualified equality condition like plain ON requires, but it doesn't silently change behavior if an unrelated same-named column is added to either table later, since the join columns are pinned explicitly in the query text.

DuckDB notes

DuckDB supports USING across all join types (INNER, LEFT, RIGHT, FULL, and even ASOF JOIN, where USING treats the last listed column as the inequality condition rather than an equality). This makes USING a genuinely useful, DuckDB-idiomatic pattern beyond just a stylistic shortcut for ordinary equi-joins.

Related terms

FAQS

USING collapses the shared join column into a single output column, while ON keeps both tables' versions of any equated column as separate, individually-qualified columns.

Yes -- USING (col1, col2) joins on the equality of both columns simultaneously, as long as both column names exist identically in both tables.

No -- USING requires you to explicitly list the shared columns to join on, while NATURAL JOIN automatically joins on every column name the two tables happen to share, which is more implicit and more fragile to schema changes.