Does COUNT() include duplicate values of a column?


#1

Question

When using the SQL COUNT() function for a column, does it include duplicate values?

Answer

Yes, when using the COUNT() function on a column in SQL, it will include duplicate values by default. It essentially counts all rows for which there is a value in the column.

If you wanted to count only the unique values in a column, then you can utilize the DISTINCT clause within the COUNT() function.

Example

/* This will return 22, the number of distinct category values. */
SELECT COUNT(DISTINCT category)
FROM fake_apps;