DISTINCT Keyword:




The distinct keyword is used with the SELECT statement to return the values that are different or distinct. The distinct keyword also eliminates the duplicated record and extracts only the unique record.

Suppose in a table you have multiple duplicate records the distinct statement will only fetch out those records that are unique.




SYNTAX

The distinct keyword can be used as in the following query:

SELECT DISTINCT column-name FROM table-name;

EXAMPLE

Suppose you have a table that is named STUDENT as follows:

STUD_ID NAME DEPT MONFEE CRSNO CDTE
100 Tim Marketing 1000 SPSS 19/06/96
100 Faddy Marketing 1000 SURVEYS 10/07/96
140 Jones Accounting 1200 TAXACCT 12/08/97
110 John Info. System 1100 SPSS 14/07/96
110 James Info. System 1100 COBOL 22/07/96
190 Abraham Finance 1200 INVESTMENT 20/06/97
150 Louis Marketing 1000 SPSS 19/06/97
150 Stuart Marketing 1000 SYSANAL 20/07/97




SELECT DISTINCT MONFEE FROM student;

It can be seen that in the MONFEE column there are some values that are same, the distinct keyword will fetch out those values that are unique. Thus the above query will generate the following result:

MONFEE
1000
1100
1200