• I did not find this to be a good introductory article on DISTINCT. I gave this article 1 star and I have "the nads to say why".

    I often see SELECT DISTINCT when doing code reviews. To me it's a red flag: Either a junior developer didn't fully understand why duplicates were being returned and did a band-aid fix by slapping on a "SELECT DISTINCT" or, they blindly copied code from some query generator that automatically adds DISTINCT whether it's needed or not.

    Also, as another poster pointed out, in the section for finding duplicate addresses (where the mysterious "AddressTable" first appears), the two "equivalent" queries are NOT the same at all! I'm not sure what the author is trying to show here, but I'm surprised the example code was published without any testing to confirm it accurately illustrates the authors point (whatever that is). I'll bet "many a newbie" will be thoroughly confused or mislead by it, though. I just hope this mistake was caused by an editing error and not by a lack of understanding.

    I'm also surprised that, although this article attempts to point out similarities between DISTINCT and GROUP BY, it doesn't really go into trade-offs between them. The most obvious to me is that with GROUP BY, it's very easy to retrieve additional information by adding aggregates (such as a count). I've found that often the first question asked after "what are the unique values?" is "how many rows are there for each of those unique values?". When using GROUP BY, all you have to do is add a count(*) to the select list. The next request is likely for an additional level of detail (eg. break-down by calendar year) which can easily be accomodated by adding another column to the select list and group by clause.

    Finally, the example using aggregates seems to be somewhat contrived. In my experience, requests to sum distinct values are very rare, but I have had to re-write queries that incorrectly summed on results from a SELECT DISTINCT.

    DISTINCTS in aggregates = BAD IDEA!

    I have much to learn, so somebody please tell me What makes SELECT DISTINCT such a 'fine bit of "SQL Spackle"'.

    Please sell me on any reason beside "clarity of code" or "easy solution" (read band-aid fix) where using SELECT DISTINCT would be preferable to using GROUP BY.