Skip to content

duplicate-column-alias

SQLstyleno fixdefault: offsql/sqlfluff

Reports two select elements with the same column name, compared without case and quotes: an alias, or the last part of a plain column reference.

The result has two columns with one name. Clients that read the result by name get only one of them, a subquery or a view built on it is rejected by some databases, and which one wins is not defined.

To fix, give one of them another alias.

Reported
...
select a, b as a from t;
...
with c as (select a from t) select * from c;
select x.a from (select * from t) as x;
...
sql:
lint:
rules:
duplicate-column-alias: warn # off (default), warn, error

Enabled by the presets: sql/sqlfluff.

Suppress one line with sudsy-disable-next-line duplicate-column-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 AL08 full