PostgreSQL DISTINCT

The PostgreSQL DISTINCT keyword is used in conjunction with SELECT statement to eliminate all the duplicate records and fetching only unique records.
There may be a situation when you have multiple duplicate records in a table. While fetching such records, it makes more sense to fetch only unique records instead of fetching duplicate records.

postgres=# SELECT name FROM tab1;           
 name  
-------
 nijam
 abu
 umar
 jamal
 abu
(5 rows)
-- From above table  tab1 having one duplicate values "name=ABU" is duplicate so DISTINCT  clause used to show without duplicate values. 
postgres=# SELECT DISTINCT(name) FROM tab1; 
 name  
-------
 umar
 jamal
 nijam
 abu
(4 rows)













No comments:

Post a Comment