DISTINCT
The DISTINCT keyword deduplicates the result set.
Example:
-- Returns the unique values from one column.
select distinct tiny_column from big_table limit 2;
-- Returns the unique combinations of values from multiple columns.
select distinct tiny_column, int_column from big_table limit 2;
DISTINCT can be used with aggregate functions (usually count functions), and count (distinct) is used to calculate how many different combinations are contained on one or more columns.
-- Counts the unique values from one column.
select count(distinct tiny_column) from small_table;
+-------------------------------+
| count(DISTINCT 'tiny_column') |
+-------------------------------+
| 2 |
+-------------------------------+
1 row in set (0.06 sec)
-- Counts the unique combinations of values from multiple columns.
select count(distinct tiny_column, int_column) from big_table limit 2;
StarRocks supports multiple aggregate functions using distinct at the same time.
-- Count the unique value from multiple aggregation function separately.
select count(distinct tiny_column, int_column), count(distinct varchar_column) from big_table;