DISTINCT

Description

DISTINCT eliminates duplicate rows from the result. SELECT DISTINCT ON eliminates rows that match on all the specified expressions.

Click here to navigate to the PostgreSQL documentation page for this syntax.

DISTINCT case

SELECT DISTINCT is supported by Snowflake.

Grammar Syntax

SELECT
   DISTINCT column1 [, ...]
FROM
   table_name;

Sample Source Patterns

Input

SELECT DISTINCT id, name FROM sample;

Output

id|name  |
--+------+
 1|Gokhan|
 2|David |
 2|Jawwad|
 4|Josue |
 1|Jack  |
 3|Josue |

DISTINCT ON case

The SELECT DISTINCT ON is translated to SELECT WITH QUALIFY to mimic the functionality.

Grammar Syntax

SELECT
   DISTINCT ON (column1,  [...,]) column2, [...,]
FROM
   table_name;

Sample Source Patterns

Input

SELECT DISTINCT ON (id) id, name FROM sample;

Output

id|name  |
--+------+
 1|Gokhan|
 2|Jawwad|
 3|Josue |
 4|Josue |

Last updated