PostgreSQL DISTINCT Keyword

The Distinct statement is used to select or fetch only the (different) Distinct data from a database table. There are many duplicate values ​​present in the database table, so Distinct is used to list different values.

DISTINCT Syntax :

The syntax of the DISTINCT statement is −

SELECT DISTINCT column1, column2,.....columnN
FROM table_name
WHERE [condition]


DISTINCT Example :

Consider the STUDENT table is having the following records

ID NAME AGE ADDRESS
1 Jugal 20 Mysore
2 Kartik 19 Delhi
3 Ashish 21 Udaipur
4 Prateek 19 Jaipur
5 Jugal 20 Mumbai
6 Prateek 19 Mumbai

The following is an example, which would fetch DISTINCT NAME record for a STUDENT.

lfcdb=# SELECT DISTINCT name FROM STUDENT;

All the above statements would create the following records in STUDENT table

NAME
Ashish
Prateek
Jugal




Visit :


Discussion



* You must be logged in to add comment.