Oracle DISTINCT Clause
Oracle DISTINCT clause is used to remove the duplicate records from the result set. It is only used with SELECT statement.
Syntax:-
Example:- We create table named with Employee and insert some records as shown in below:
Execute this query:- In the above table Employee state such as Bihar many time entry. When we use Distinct clause then get following output.
Syntax:-
SELECT DISTINCT expressions FROM tables WHERE conditions;
Example:- We create table named with Employee and insert some records as shown in below:
CREATE TABLE Employee ( Empcode varchar2(30) primary key, Name varchar2(100), Age number(5), Salary numeric(10,2), Email varchar2(200), State varchar2(100) CONSTRAINT Employee_pk PRIMARY KEY (Empcode) ); //Insert some records as shown below:- Insert into Employee(Empcode,Name,Age,Salary,Email,State) values('Emp1001','Santosh Kumar Singh',22,12000,'s@gmail.com','Bihar') Insert into Employee(Empcode,Name,Age,Salary,Email,State) values('Emp1002','Reena kumari',25,15000,'r@gmail.com','Bihar') Insert into Employee(Empcode,Name,Age,Salary,Email,State) values('Emp1003','Anu Singh',21,14000,'a@gmail.com','UP') Insert into Employee(Empcode,Name,Age,Salary,Email,State) values('Emp1004','Gagan Agrawal',24,11000,'g@gmail.com','Haryana') Insert into Employee(Empcode,Name,Age,Salary,Email,State) values('Emp1005','Suraj',21,13000,'su@gmail.com','Bihar') Insert into Employee(Empcode,Name,Age,Salary,Email,State) values('Emp1006','Pramod kumar sah',27,14000,'pk@gmail.com','New Delhi')
Execute this query:- In the above table Employee state such as Bihar many time entry. When we use Distinct clause then get following output.
select distinct State from Employee