Site icon Narayana Tutorial

SQL DISTINCT


In this tutorial post, we are going discussing how to Eliminating Duplicate Records from the table.

SQL DISTINCT

 

Consider we have EMPLOYEE demo table which is using for the executing DISTINCT command

EMP_ID EMP_NAME EMP_DESIGNATION EMP_GENDER EMP_QUALIFICATION EMP_LOCATION
100 Narayanaswamy Sr.Software Engineer Male MCA Chennai
101 Kumar Quality Analyst Male B.Tech Chennai
102 Ramesh Database Administration Male B.Tech Chennai
100 Narayanaswamy Sr.Software Engineer Male MCA Chennai

 

Selected all columns and all rows

 

Syntax:

SELECT DISTINCT  *  FROM <Table-Name>;

Query:

SELECT DISTINCT * FROM EMPLOYEE;

The above query scan entire rows, and eliminates rows which are having same content in each column.

Output

EMP_ID EMP_NAME EMP_DESIGNATION EMP_GENDER EMP_QUALIFICATION EMP_LOCATION
100 Narayanaswamy Sr.Software Engineer Male MCA Chennai
101 Kumar Quality Analyst Male B.Tech Chennai
102 Ramesh Database Administration Male B.Tech Chennai

 

Selected columns and all rows

 

Syntax:

SELECT DISTINCT  <Column-Name 1>  FROM <Table-Name>;

Query:

SELECT DISTINCT EMP_QUALIFICATION FROM EMPLOYEE;

The above query scan entire rows, and eliminates rows which are having same content in EMP_QUALIFICATION column.

Output:

EMP_QUALIFICATION
MCA
B.Tech