Logical order, third verse: windows run with SELECT (after WHERE and GROUP BY, before DISTINCT and ORDER BY) — the same sequence that made QUALIFY necessary. Consequences run both ways: any per-row window defeats DISTINCT silently; and 'DISTINCT then window' can't be one flat query (the window would see pre-dedup rows) — it needs subquery staging. The tell: 'DISTINCT stopped working when I added a column' — the column was a window.
SELECT DISTINCT color, ROW_NUMBER() OVER () AS rn FROM p ORDER BY rn;
SELECT color, ROW_NUMBER() OVER () AS rn FROM ( SELECT DISTINCT color FROM p ) ORDER BY rn;
Adding ROW_NUMBER kept both identical 'teal' rows — windows compute before DISTINCT, so the row number made the duplicates unique and DISTINCT found nothing to collapse; staging the dedup first fixes it.
Stage it — a subquery for whichever runs first by intent; never DISTINCT across a per-row window and expect collapse.