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

E0009 duplicate-name

Table alias or CTE name given twice in one query.

CodeNameCategoryDefault
E0009duplicate-namecorrectnesserror

What it reports

A FROM clause gives the same name twice (an alias, or a table name without an alias), or a WITH clause defines two CTEs with the same name. The database rejects the query: a qualified reference like o.id could mean either.

Example

SELECT o.id FROM orders o JOIN users o ON o.id = o.user_id;
error[E0009]: Table name 'o' is specified more than once in FROM
  --> q.sql:1:38
    |
  1 | SELECT o.id FROM orders o JOIN users o ON o.id = o.user_id;
    |                                      ^
    = help: Give each occurrence a different alias

Fixed:

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

Notes

Two tables with the same name in different schemas (FROM auth.users, public.users) are fine, and so is a name reused in a subquery. Checked for PostgreSQL, Redshift and MySQL (where aliases are case sensitive); SQLite accepts a repeated table alias, so only its repeated CTE names are reported.

Configuring

# sqlsift.toml
[rules]
duplicate-name = "warn"   # or "off"

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