Troubleshooting “Ambiguous column name” errors in joined SQL views.

The error “Ambiguous column name ‘ColumnName'” occurs when a SQL query or database view joins two or more tables that contain identical column names, and a column reference in the SELECT, WHERE, ON, GROUP BY, or ORDER BY clause does not specify which table the column belongs to. When Excel queries such a view or executes a custom joined SQL statement, the database engine cannot determine which table’s column should be returned or evaluated, causing the connection to fail.

Quick Answer

To fix an “Ambiguous column name” error, prefix the conflicting column name with its table name or table alias (for example, change SELECT CustomerID to SELECT o.CustomerID or SELECT Orders.CustomerID). If two joined tables share column names in the SELECT list, assign unique aliases using the AS keyword (such as o.ID AS OrderID, c.ID AS CustomerID).


Why Ambiguity Breaks SQL Queries in Excel

Relational database tables frequently share common naming conventions. For example, an Orders table and a Customers table will often both contain a column named CustomerID or ModifiedDate.

When you write a single-table query, table prefixes are optional:

SELECT CustomerID, ModifiedDate FROM dbo.Orders;

However, as soon as a JOIN is introduced:

-- This will trigger "Ambiguous column name 'CustomerID'"
SELECT CustomerID, OrderDate, TotalDue
FROM dbo.Orders
INNER JOIN dbo.Customers
    ON dbo.Orders.CustomerID = dbo.Customers.CustomerID;

Because CustomerID exists in both dbo.Orders and dbo.Customers, the database engine halts execution.

This error surfaces in Excel in three common scenarios:

  1. Writing a custom SQL query directly inside Power Query’s Advanced options dialog.
  2. Connecting Excel to a pre-existing SQL View where the view’s internal code contains unaliased duplicates.
  3. Adding a step in Power Query that filters a joined native query, causing Power Query to wrap the query and generate an ambiguous column reference.

For guidance on maintaining query stability across database views, see Managing SQL Query Stability: Fixing Timeouts and Resource Exhaustion..


Step-by-Step Fixes

Method 1: Qualify the Column with Table Aliases

Every column referenced in a multi-table query should be explicitly linked to its parent table using a short alias.

  1. Open your query in Excel’s Power Query Editor.
  2. Click Source in the Applied Steps list, then click the gear icon (or open the Advanced Editor).
  3. Update the SQL query by assigning single-letter or short aliases to each table:
    • Broken: SELECT OrderID, CustomerID, OrderDate FROM dbo.Orders JOIN dbo.Customers ON Orders.CustomerID = Customers.CustomerID
    • Corrected: SELECT o.OrderID, o.CustomerID, o.OrderDate FROM dbo.Orders AS o JOIN dbo.Customers AS c ON o.CustomerID = c.CustomerID
  4. Click OK.

Method 2: Assign Unique Aliases to Duplicate Columns

If your Excel report needs to display data from columns with identical names across both tables, rename them in the SELECT clause using the AS keyword.

SELECT
    o.ID AS OrderID,
    c.ID AS CustomerID,
    o.CreatedDate AS OrderCreatedDate,
    c.CreatedDate AS CustomerRegisteredDate,
    o.Status AS OrderStatus,
    c.Status AS AccountStatus
FROM dbo.Orders AS o
INNER JOIN dbo.Customers AS c
    ON o.CustomerID = c.CustomerID;

Assigning clear, distinct aliases resolves the ambiguity on the database server and ensures that Power Query imports clean column headers into your Excel workbook.

Method 3: Avoid SELECT * in Joined Views and Queries

Using SELECT * across joined tables is a primary cause of unexpected ambiguity errors.

-- Highly prone to breakage:
SELECT *
FROM dbo.Invoices AS i
JOIN dbo.Vendors AS v ON i.VendorID = v.VendorID;

Even if SELECT * runs today, it will fail tomorrow if a database administrator adds a new column (such as RowVersion or Notes) to both tables. The database view will immediately throw an ambiguous column error upon refresh.

Always replace SELECT * with an explicit list of table-qualified column names.

If updating an underlying view or query causes column matching issues in existing workbooks, follow Fixing “The column ‘X’ of the table wasn’t found” after a Schema change..


Diagnostic Next Steps

If you have fixed all column prefixes but errors continue during refresh: