SQL Server error 209: Ambiguous column name
Two or more tables in the query have a column with this name, so SQL Server can't tell which one you mean. Prefix it with a table alias.
- Error number
209- Severity
- 16
- Category
- Names and objects
What it means
When several joined tables share a column name, such as Id or CustomerId, an unqualified reference could mean any of them. SQL Server refuses to guess and raises 209.
Common causes
- Joining tables that share a column name and using that name without a prefix in
SELECT,WHERE,ORDER BYorGROUP BY. - A column added to one table later, which makes previously unique names ambiguous in existing queries.
How to fix it
-
Qualify the column with its table alias.
SELECT o.CustomerId, c.Name FROM dbo.Orders AS o JOIN dbo.Customers AS c ON c.CustomerId = o.CustomerId ORDER BY o.CustomerId;
-
Always qualifying columns in multi-table queries prevents this when someone adds a column later.
Related errors
207Invalid column name4104Multi-part identifier not bound42702PostgreSQL: column reference is ambiguous1052MySQL: Column is ambiguousORA-00918Oracle: column ambiguously defined
More names and objects errors
208Invalid object name2812Could not find stored procedure2714There is already an object named3701Cannot drop, object not found3702Cannot drop database, currently in use5030Database couldn't be exclusively locked8144Too many arguments specified8145Is not a parameter for procedure
The code and message text are from the Microsoft Database Engine events and errors reference. Browse the full SQL Server error list or search every database error.
Work on SQL Server in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for SQL Server and the other databases you use.