Oracle: DISTINCT Clause

DISTINCT Clause in Oracle is used to remove the duplicate entries from the table. The clause is always used to filter the duplicate values from the SELECT statement.


Select DISTINCT Column from Table_name


Suppose we have Stu Table as follows:

Distinct Clause

We can find from the above table that we have 2 duplicate entries in common. 

1. So if we apply Distinct Clause on all columns of the Stu Table:

Select DISTINCT * from Stu;


Distinct Clause

2) If we want to apply DISTINCT Clause in only Roll_no, Name Clause:

Select DISTINCT Section, Name from Stu;


Distinct Clause

Note that in output we are displayed B in the Section column multiple times. This is because When we apply the DISTINCT Clause with multiple columns the compiler considers the entries in a pair. However, Section and Name form a single pair. In the above output, despite having similar Roll_no their alternative pair have different names. This is why they are not considered duplicates here.