SQL Functions and Aggregation/Count distinct values

Count unique entries in a column.

Section: Advanced Aggregation

Count distinct values

sql
sql
SELECT COUNT(DISTINCT customer_id) AS unique_customers
FROM orders;
Explanation

Distinct counts are common in analytics and business reporting.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Advanced Aggregation
Conditional aggregation with CASE
Compute multiple categorized totals in one query.
OpenIn sheetsqlsame section
Aggregate by date
Roll up metrics by calendar day.
OpenIn sheetsqlsame section
Concatenate strings
Join multiple strings into one value.
Get current date and timestamp
Return the current date and current timestamp.
Use CASE expression
Return different values based on conditions.
Change case
Convert strings to uppercase or lowercase.