>_QueryLocalCSV & JSON tools that run in your browser

How do I count unique values in a column with SQL?

SELECT COUNT(DISTINCT customer) AS unique_customers FROM data;

Run this query on the demo dataset →

COUNT(DISTINCT column) counts how many different values appear in a column, ignoring duplicates — different from plain COUNT(*), which would count every row even if the same customer placed five orders. This answers 'how many distinct customers/products/countries do I actually have', not 'how many rows mention one'.

A table named data with columns: order_id (integer), customer (text), country (text), category (text), quantity (integer), unit_price (real), order_date (text, YYYY-MM-DD).

Want to run it on your own file? Open it with Count rows in a CSV: your file becomes the table data, and you can paste this query with your own column names.

Related recipes