• A good introduction to Distinct for novices, though it it really doesnt explain why you would consider using a Group by to get a distinct list, is there a performance differential to consider when using one method or the other?

    I also consider that these two SQL scripts are completely different and thus shouldnt be considered alternatives for each other

    SELECT PostCode, COUNT(Postcode)

    FROM

    (

    SELECT DISTINCT Address1, Address2, City, Postcode

    FROM AddressTable

    ) AS Sub

    GROUP BY Postcode

    HAVING COUNT(Postcode) > 1

    and

    SELECT Address1,Address2,City,PostCode,Count(PostCode)

    FROM AddressTable

    GROUP BY Address1,Address2,City,PostCode

    HAVING Count(PostCode) > 1

    The first one would work on the following list of data

    B23 3SP, 1

    EC1A 3AD, 2.

    which would result in only the EC1A 3AD, 2 row being returned, however the alternative query works on a totally different set of data, whch may be :

    6 some road, some district, B23 6QD, 1

    8 another road, another district, EC1A 3AD, 1

    10 another road, another district, EC1A 3AD, 1

    So with the Having Count()>1 clause you would get no results returned.

    _________________________________________________________________________
    SSC Guide to Posting and Best Practices