Ambiguous Column Reference
Error message
column reference is ambiguous
Quick summary
You referenced a column name that exists in more than one table in the query, without specifying which table.
Why this happens
Two joined tables have a column with the same name (e.g., both have
id)Using an unqualified column name in a multi-table query
Aliasing a column to a name that conflicts with another column
Minimal example
SELECT id, name FROM users
INNER JOIN orders ON orders.user_id = users.id;
-- 'id' exists in both users and orders → ambiguousSELECT users.id AS user_id, orders.id AS order_id, users.name
FROM users
INNER JOIN orders ON orders.user_id = users.id;Qualifying id with the table name and adding aliases makes it clear which id is meant.
How to diagnose
Identify which tables in the query have a column with the same name
Check if the unqualified column name appears in multiple tables
How to fix
Qualify the column with the table name or alias:
table.columnoralias.columnUse a column alias to disambiguate:
SELECT a.id AS user_idRename the column in one table if the conflict is a design issue
How to prevent
Always qualify column names with table aliases in multi-table queries
Use consistent table aliases in queries
Avoid naming every primary key
id— useuser_id,order_id, etc. in joins