COUNTDISTINCT
COUNTDISTINCT refers to the SQL construct used to count the number of distinct (non-NULL) values in a column or expression. The standard form is COUNT(DISTINCT expression), an aggregate function that returns the number of unique values produced by the expression within the query’s scope. It is supported by most relational database systems, though syntax can vary for counting distinct across multiple columns. Unlike COUNT(*), which returns the total number of rows, COUNT(DISTINCT ...) counts unique values only. NULL values are not counted by COUNT(DISTINCT ...).
Usage examples: In a table orders with a customer_id, you can count how many different customers placed
NULL handling and performance: NULL values are ignored in COUNT(DISTINCT). When many values are distinct, the
Dialect notes: Syntax and capabilities vary by database. Most systems implement COUNT(DISTINCT column) for a single