Distinct in DBMS

This keyword allows the user to select the different value tuples from the table. Consider a query which has to pull ages from the STUDENT table, who are studying COURSE_001. Simply pulling the ages like below will retrieve all the ages from the STUDENT table. It will not give the set of different values for the ages of students.

SELECT AGE FROM STUDENT WHERE COUSER_ID = ‘COURSE_001’;

In order to get different values for the ages, we use DISTICT keyword in above query. Then it will select different values of ages from student table.

SELECT DISTINCT AGE FROM STUDENT WHERE COUSER_ID = ‘COURSE_001’;

Suppose we have used DISTINCT query as below:

SELECT DISTINCT COUSER_ID, AGE FROM STUDENT;

This query will select different combination of COURSE_ID and AGE from the STUDENT table.

Translate »