// SQL Server error reference

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
Error message
Ambiguous column name '%.*ls'.

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 BY or GROUP BY.
  • A column added to one table later, which makes previously unique names ambiguous in existing queries.

How to fix it

  1. 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;
  2. Always qualifying columns in multi-table queries prevents this when someone adds a column later.

Related errors

More names and objects errors

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.

// fewer errors, faster fixes

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.