PostgreSQL DISTINCT Keyword

PostgreSQL DISTINCT Keyword is used with select statement to eliminate duplicate(different values) values. Two rows are considered distinct if they are differ in at least one column value. Null values are considered equal in comparison.

Syntax:

SELECT DISTINCT select_list …

PostgreSQL DISTINCT Example:

Table for below example:

student_name | rollnumber | class | country --------------+------------+-------+--------- Vijay | 1001 | 12 | India James | 1003 | 10 | USA George | 1002 | 10 | UK Vinod | 1004 | 8 | UK Michael | 1006 | 8 | Germany

The following SQL statement selects only the distinct values from the “country” columns from the “students” table

k2info=# select distinct country from students;
country
———
India
Germany
USA
UK
(4 rows)

Powered by k2schools