Recently I tried script from 'T-SQL Querying book (2005)' and it failed. I looked into the code and couldn't find anything wrong. It violated PK constraint (wait_type) but using distinct (and group by) didn't show any duplications. Eventually I found the
rows that cause the issue and there are identical but are not removed using neither distinct nor group by.