PostgreSQL Distinct

PostgreSQL Distinct

The PostgreSQL DISTINCT is used to eliminate duplicate records from a table or a query.

Distinct syntax

-- select distinct column records from table
SELECT DISTINCT column_name FROM table_name

-- select specific columns 
SELECT DISTINCT column_name1, column_name2 FROM table_name

Distinct example

Goods table

idgood_typenamedescriptionpriceinsert_date
1ACar_1Car 1 description1002018-07-21 08:45:57.311809
2ACar_2Car 2 description2002018-07-21 08:45:57.311809
3ACar_3Car 3 description1002018-07-21 08:45:57.311809
4BBoat_4Boat 4 description5002018-07-21 08:45:57.311809
5BBoat_5Boat 5 description3002018-07-21 08:45:57.311809
6CTrain_1Train 123 description8002018-07-21 08:45:57.311809
SELECT DISTINCT good_type FROM goods;

Result

good_type
B
C
A
SELECT DISTINCT good_type, price FROM goods;

Result

good_typeprice
B500
B300
A200
C800
A100