DISTINCT keyword

SELECT DISTINCT is used to return only distinct (i.e different) values from a column as part of a SELECT statement.

Syntax

SELECT DISTINCT columnName [, columnName ...]
FROM tableName;

Examples

The following query returns every unique symbol traded in the last hour.

Distinct symbolsDemo this query
SELECT DISTINCT symbol
FROM fx_trades
WHERE timestamp IN '$now - 1h..$now';

SELECT DISTINCT can be used with aggregation functions and filters.

With aggregateDemo this query
SELECT DISTINCT symbol, count()
FROM fx_trades
WHERE timestamp IN '$today';
With filterDemo this query
SELECT DISTINCT symbol, side, count()
FROM fx_trades
WHERE timestamp IN '$today'
AND price > 1;