Skip to content

duplicate-table-alias

SQLcorrectnessno fixdefault: warnsql/sqlfluff

Reports two tables of one FROM clause with the same alias, or the same name when there is no alias.

A column reference with that alias can mean either table. Databases reject the query as ambiguous, or the query reads the wrong one.

To fix, give each table its own alias.

Reported
...
select distinct a from t;
select a from t group by a;
...
select a from t as x join u as x on x.a = x.b;
select a from t join u on t.a = u.a join t on t.a = t.b;
select a from t join u on t.a = u.a join v on t.a = v.b;
...
with recursive r as (select 1 union all select n from r) select 2;
sql:
lint:
rules:
duplicate-table-alias: warn # off, warn (default), error

Enabled by the presets: sql/sqlfluff.

Suppress one line with sudsy-disable-next-line duplicate-table-alias in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
sqlfluff AL04 full