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
A NATURAL JOIN automatically joins two tables on all columns that share the same name, without an explicit ON or USING clause.
JOIN clause →How do SQL JOINs work? Learn INNER, LEFT, RIGHT, FULL OUTER, CROSS, and ASOF joins with syntax examples — plus how to join directly against CSV and Parquet files.
ASOF JOIN →An ASOF JOIN matches each row in one table to the closest preceding (or following) row in another table based on an ordering column, commonly a timestamp -- a core building block for time-series analysis.
CROSS JOIN →A CROSS JOIN produces the Cartesian product of two tables, pairing every row from the first table with every row from the second.
SELF JOIN →A self join joins a table to itself, typically using table aliases to compare rows within the same table to each other.
WHERE clause →The WHERE clause filters rows in a SQL query based on a boolean condition, keeping only rows for which the condition evaluates to true.
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.
