What's the difference between these two clauses in SQL?

The two clauses are:

SELECT DISTINCT COUNT (V_CODE) FROM PRODUCT;

and

SELECT COUNT (DISTINCT V_CODE) FROM PRODUCT;

1 Answer

Relevance
  • 8 years ago
    Favorite Answer

    In the first, DISTINCT serves no purpose - the COUNT will only return a single value in any case, so it'd be distinct by default. The result will be the number of rows in PRODUCT.

    In the second, the DISTINCT V_CODE result is a collection of the unique values of V_CODE within table PRODUCT. The COUNT will then result in the number of those unique values, which will be some value less than or equal to that of the first query.

Still have questions? Get your answers by asking now.