DISTINCT clause in Oracle

ORACLE DISTINCT
To eliminate the duplicate records from the result set, Oracle DISTINCT clause is used, but only with the SELECT statement.

Syntax:

SELECT DISTINCT columns  
FROM tables  
WHERE conditions;  

Parameters:
columns: It is used to specify the columns to be selected.
table_name: It is used to specify the name of the table from which the data needs to be removed.
conditions: It is used to specify the conditions to be strictly fulfilled for the action to complete.

Example: Using Distinct Select for single column.
Students table:

STUDENT_ID STUDENT_NAME STUDENT_AGE
1 Joy 5
2 Smiley 13
3 Happy 11

Distinct Select Query:

SELECT DISTINCT student_name  
FROM students  
WHERE student_id = 2;

Output:

STUDENT_NAME
Smiley

Explanation:
The ‘students’ is an already existing table. Here we are trying to specify the distinct name of the student whose ID is equal to 2.

Example: Using Distinct Select for multiple column.
Students table:

STUDENT_ID STUDENT_NAME STUDENT_AGE
1 Joy 5
2 Smiley 13
3 Happy 11

Distinct Select Query:

SELECT DISTINCT student_name, student_age
FROM students  
WHERE student_id >= 2;

Output:

STUDENT_NAME STUDENT_AGE
Smiley 13
Happy 11

Explanation:
The ‘students’ is an already existing table. Here we are trying to specify the distinct name and age of the students whose student_id is greater than or equal to 2.