Skip to content
SQL errors / “Column Reference Is Ambiguous” — Fix a SQL JOIN Error
SQL error

“Column Reference Is Ambiguous” — Fix a SQL JOIN Error

Both joined tables have that column name, so the database refuses to guess.

The exact message
DuckDB
Binder Error: Ambiguous reference to column name "customer_id" (use: "customers.customer_id" or "orders.customer_id")
PostgreSQL
column reference "customer_id" is ambiguous
SQL Server
Ambiguous column name 'customer_id'.
MySQL
Column 'customer_id' in field list is ambiguous
SQLite
ambiguous column name: customer_id

The symptom

You join two tables and the query fails with an error like "column reference 'customer_id' is ambiguous" or "ambiguous column name". Both tables have a column with that name, so the database refuses to guess which one you meant.

The quick fix

Prefix the ambiguous column with its table name or alias. Change an unqualified reference such as customer_id to c.customer_id or o.customer_id, depending on which table you mean.

The query that fails
select customer_id, order_date
from customers
join orders on orders.customer_id = customers.customer_id

Running it raises Ambiguous reference to column name.

The corrected query
select c.customer_id,
       c.first_name,
       o.order_date
from customers as c
join orders    as o on o.customer_id = c.customer_id
order by o.order_date

Open the corrected query in the playground

Why it happens

After a JOIN, the result has columns from every table. When two of them have the same name, an unqualified reference in SELECT, WHERE, ORDER BY, or GROUP BY is genuinely ambiguous, and SQL treats that as an error rather than silently picking one. Aliasing every table and qualifying shared columns prevents the error from returning as the query grows.

Watch out

A column that lives in only one table does not strictly need qualifying, but adding an alias to a query and forgetting to qualify a now-ambiguous column is a common way to introduce this error later. Qualify shared columns from the start.

How other engines word it

Engine Message
DuckDB Binder Error: Ambiguous reference to column name "customer_id" (use: "customers.customer_id" or "orders.customer_id")
PostgreSQL column reference "customer_id" is ambiguous
SQL Server Ambiguous column name 'customer_id'.
MySQL Column 'customer_id' in field list is ambiguous
SQLite ambiguous column name: customer_id

Related errors

Learn more