[thelist] Finding NON-unique values in MS SQL

Paul Cowan evolt at funkwit.com
Wed Jul 3 19:21:01 CDT 2002

Anthony wrote:
> If you are just interested in "repeats" in a single column this should
> select Count(IDF), IDF from TableName
>     where Count(IDF) > 1
>     group by IDF


Given that the "where" is on a aggregated column (count(IDF)) you
can't use "where". You need "having", which is applied AFTER the aggregates
(including 'group by').


    select Count(IDF), IDF from TableName
    group by IDF
    having Count(IDF) > 1

should tell you any duplicate IDFs.

Hope this helps!


More information about the thelist mailing list