Skip to content

union-distinct

SQLsuspiciousno fixdefault: warnsql/sqlfluff

Reports a UNION that names neither DISTINCT nor ALL.

UNION removes duplicates, which costs a sort or a hash, and UNION ALL does not. Without a keyword a reader cannot tell whether the removal is wanted, or whether ALL was forgotten.

To fix, write UNION DISTINCT or UNION ALL.

Reported
select 1 union select 2;
select 1 union all select 2;
select 1 union distinct select 2;
...
sql:
lint:
rules:
union-distinct: warn # off, warn (default), error

Enabled by the presets: sql/sqlfluff.

Suppress one line with sudsy-disable-next-line union-distinct 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 AM02 full