View a markdown version of this page

DISTINCT and ALL - Amazon Athena
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

DISTINCT and ALL

SELECT DISTINCT returns each distinct row of the result once. SELECT ALL, the default, keeps duplicate rows.

Syntax

SELECT DISTINCT select_list

Examples

For a description of the sample tables that the examples on this page use, see SELECT statement in DuckDB.

The following SQL query returns each region once.

SELECT DISTINCT region FROM sales_db.sales_parquet ORDER BY region

The query returns the following results.

region

east

north

west

Considerations

To keep one row for each distinct value of some columns, filter on row_number() in a QUALIFY clause. For example, QUALIFY row_number() OVER (PARTITION BY region ORDER BY amount DESC NULLS LAST) = 1 keeps the largest order in each region. For more information about QUALIFY, see QUALIFY clause.