Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

E0006 ambiguous-column

Column reference is ambiguous across tables.

CodeNameCategoryDefault
E0006ambiguous-columncorrectnesserror

What it reports

An unqualified column name exists in more than one table in scope, so the database would reject the query.

Example

SELECT id FROM users JOIN orders ON orders.user_id = users.id;
error[E0006]: Column 'id' is ambiguous (found in tables: users, orders)
  --> q.sql:1:8
    |
  1 | SELECT id FROM users JOIN orders ON orders.user_id = users.id;
    |        ^^
    = help: Qualify the column with a table name: users.id

Fixed:

SELECT users.id FROM users JOIN orders ON orders.user_id = users.id;

Notes

Columns joined with USING or NATURAL JOIN are not ambiguous and are not reported.

A CTE or subquery whose SELECT * covers a join can output the same column name twice; referring to that name is ambiguous too (qualified or not):

WITH j AS (SELECT * FROM users JOIN orders ON orders.user_id = users.id)
SELECT id FROM j;
error[E0006]: Column 'id' is ambiguous (CTE 'j' has more than one column named 'id')

This is reported in every dialect except SQLite, which resolves the name to the first such column. Names sqlsift guesses for unaliased expressions (count(*) is count in PostgreSQL but count(*) in MySQL) are never compared.

Configuring

# sqlsift.toml
[rules]
ambiguous-column = "warn"   # or "off"

Or for a single line: -- sqlsift:disable E0006. The examples use the schema on the Rules page.