SQL Keywords

SQL USING

What is the SQL USING clause?

USING specifies one or more common column names to build an equality condition for JOIN or to supply a source dataset in MERGE.
Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Compatible dialects for SQL USING:

SQL USING Full Explanation

USING is an ANSI-SQL keyword that appears in two major contexts.1. JOIN ... USING (col1, col2) – Replaces a verbose ON clause when the joined tables share identically named columns. The database automatically builds an equality predicate for every listed column and removes duplicated columns from the result set, returning only one copy of each USING column.2. MERGE ... USING source_table – Supplies the source table, view, or sub-query that will be compared to the target table during an upsert operation.Behavior:- Equivalent to writing ON t1.col = t2.col AND ...- The join type (INNER, LEFT, RIGHT, FULL) determines which unmatched rows appear.- Column disambiguation: after the join, the USING columns are referenced without qualification; other columns still need table aliases if ambiguous.- In MERGE, the USING clause acts similarly to the FROM clause, exposing source columns to the match condition and action clauses.Caveats:- All listed columns must exist in both tables and have comparable data types.- USING cannot mix with ON in the same JOIN level.- Some databases (e.g., SQL Server) support USING only inside MERGE, not JOIN.

SQL USING Syntax

-- JOIN form
SELECT ...
FROM table_a AS a
JOIN table_b AS b USING (id, tenant_id);

-- MERGE form (PostgreSQL style)
MERGE INTO target t
USING source s
ON (t.id = s.id)
WHEN MATCHED THEN UPDATE SET col = s.col
WHEN NOT MATCHED THEN INSERT (id, col) VALUES (s.id, s.col);

SQL USING Parameters

  • column_list (list) - One or more column names existing in both joined tables, used to build equality predicates.
  • source_table (table) - view|||subquery|||Dataset compared to the target during the merge.
  • alias (identifier) - Optional name to reference the source rows.

Example Queries Using SQL USING

-- 1. Inner join orders and payments on shared order_id
SELECT o.order_id, o.created_at, p.amount
FROM orders o
JOIN payments p USING (order_id);

-- 2. Left join with multiple USING columns
SELECT *
FROM customers c
LEFT JOIN subscriptions s USING (customer_id, tenant_id);

-- 3. PostgreSQL MERGE example
MERGE INTO inventory AS inv
USING latest_counts AS src
ON (inv.sku = src.sku)
WHEN MATCHED THEN UPDATE SET quantity = src.quantity
WHEN NOT MATCHED THEN INSERT (sku, quantity) VALUES (src.sku, src.quantity);

Expected Output Using SQL USING

  • Returns rows where orders.order_id equals payments.order_id.
  • Returns every customer; subscription columns are NULL when no match.
  • Updates existing inventory rows with new quantities or inserts new SKUs.

Use Cases with SQL USING

  • Simplify equality joins on identically named keys
  • Prevent column duplication in result sets
  • Write cleaner, less error-prone SQL compared to long ON clauses
  • Feed a source dataset into a MERGE/UPSERT statement

Common Mistakes with SQL USING

  • Listing a column that exists in only one table – results in an error
  • Mixing USING and ON in the same JOIN – syntax error
  • Assuming USING keeps both duplicate columns – it drops one copy
  • Forgetting that SQL Server accepts USING only in MERGE, not JOIN

Related Topics

First Introduced In

SQL:1999

Frequently Asked Questions

What databases support JOIN ... USING?

PostgreSQL, MySQL, MariaDB, Oracle, SQLite, Snowflake, BigQuery, DuckDB, and others. SQL Server is the main hold-out.

Why are duplicate columns removed when USING is used?

The SQL standard defines USING to coalesce the matched columns into one, because their values are guaranteed to be equal. This keeps result sets tidy.

How is USING different from NATURAL JOIN?

NATURAL JOIN automatically takes all identically named columns, which can be dangerous. USING forces you to list the columns explicitly, making intent clear and predictable.

Can I reference a USING column without a table alias?

Yes. After the join, the column is unqualified. You can still qualify it if you prefer, but it is not required.

Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.
Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo

Check out other commonly used SQL Keywords!