ORACLE | ||||||||
| ||||||||
| ||||||||
| ||||||||
| ||||||||
| ||||||||
| ||||||||
| ||||||||
|
Oracle - Distinct
In Oracle, DISTINCT clause is used to remove the duplicate records from the result set. It is only used with SELECT statement.
SELECT DISTINCT expressions
FROM tables
WHERE conditions;
Let's take a table "customers"
CREATE TABLE "CUSTOMERS"
( "NAME" VARCHAR2(4000),
"AGE" NUMBER,
"SALARY" NUMBER,
"STATE" VARCHAR2(4000)
)
/
Name | Age | Salary | City |
---|---|---|---|
Seethu | 16 | 12000 | Bangalore |
Nithya | 21 | 25000 | Bangalore |
Sanvika | 26 | 56000 | Bangalore |
Pranvitha | 21 | 25000 | Hyderabad |
Sresta | 21 | 23000 | Hyderabad |
Gauri | 27 | 27000 | Hyderabad |
Danush | 31 | 31000 | Maharashtra |
Pralaynath | 65 | 76000 | Kerala |
Pranav | 68 | 87000 | Kerala |
SELECT DISTINCT state
FROM customers
WHERE name = 'Sresta';
CITY |
---|
Hyderabad |
SELECT DISTINCT name, age, salary
FROM customers
WHERE age >= '60';
name | age | salary |
---|---|---|
Pralaynath | 65 | 76000 |
This example specifies distinct name, age and salary of the customer where age is greater than or equal to 65.