Skip to content

AM01 — DISTINCT is redundant with GROUP BY

Group: Ambiguity · Auto-fixable: no

GROUP BY already yields one row per group, so a leading DISTINCT only adds a needless sort. Drop the DISTINCT. (DISTINCT ON is a different feature — see ST08.)

bad: SELECT DISTINCT a FROM t GROUP BY a
good: SELECT a FROM t GROUP BY a

Disable this rule in banshee.toml:

[lint]
exclude = ["AM01"]

Or silence one line with -- noqa: AM01. See Linting.