create table testdup
(
id number(10) not null,
name varchar2(150) not null,
dept number(10) not null,
salary number(10) not null
)
insert into testdup values(1,'Mukesh Kumar',12,11000);
insert into testdup values(1,'Mukesh Kumar',12,11000);
insert into testdup values(1,'Mukesh Kumar',12,11000);
insert into testdup values(1,'Mukesh Kumar',12,11000);
insert into testdup values(1,'Mukesh Kumar',12,11000);
insert into testdup values(1,'Mukesh Kumar',12,11000);
insert into testdup values(1,'Mukesh Kumar',12,11000);
insert into testdup values(1,'Mukesh Kumar',12,11000);
insert into testdup values(1,'Mukesh Kumar',12,11000);
insert into testdup values(1,'Mukesh Kumar',12,11000);
insert into testdup values(1,'Mukesh Kumar',12,11000);
insert into testdup values(2,'Nitin Kumar',13,21000);
insert into testdup values(2,'Nitin Kumar',13,21000);
insert into testdup values(2,'Nitin Kumar',13,21000);
insert into testdup values(2,'Nitin Kumar',13,21000);
insert into testdup values(2,'Nitin Kumar',13,21000);
insert into testdup values(2,'Nitin Kumar',13,21000);
insert into testdup values(2,'Nitin Kumar',13,21000);
insert into testdup values(2,'Nitin Kumar',13,21000);
insert into testdup values(2,'Nitin Kumar',13,21000);
insert into testdup values(2,'Nitin Kumar',13,21000);
insert into testdup values(3,'Bipin Kumar',14,25000);
insert into testdup values(3,'Bipin Kumar',14,25000);
insert into testdup values(3,'Bipin Kumar',14,25000);
insert into testdup values(3,'Bipin Kumar',14,25000);
insert into testdup values(3,'Bipin Kumar',14,25000);
insert into testdup values(3,'Bipin Kumar',14,25000);
insert into testdup values(3,'Bipin Kumar',14,25000);
insert into testdup values(3,'Bipin Kumar',14,25000);
insert into testdup values(3,'Bipin Kumar',14,25000);
insert into testdup values(3,'Bipin Kumar',14,25000);
Select * from TestDup
output:
ID Name Dept Salary
1 Naween Kumar 10 10000
2 Neeraj Kumar 11 15000
3 Nitin Kumar 12 21000
1 Mukesh Kumar 12 11000
1 Mukesh Kumar 12 11000
1 Mukesh Kumar 12 11000
1 Mukesh Kumar 12 11000
1 Mukesh Kumar 12 11000
1 Mukesh Kumar 12 11000
1 Mukesh Kumar 12 11000
1 Mukesh Kumar 12 11000
1 Mukesh Kumar 12 11000
1 Mukesh Kumar 12 11000
2 Nitin Kumar 13 21000
2 Nitin Kumar 13 21000
2 Nitin Kumar 13 21000
2 Nitin Kumar 13 21000
2 Nitin Kumar 13 21000
2 Nitin Kumar 13 21000
2 Nitin Kumar 13 21000
2 Nitin Kumar 13 21000
2 Nitin Kumar 13 21000
2 Nitin Kumar 13 21000
3 Bipin Kumar 14 25000
3 Bipin Kumar 14 25000
3 Bipin Kumar 14 25000
3 Bipin Kumar 14 25000
3 Bipin Kumar 14 25000
3 Bipin Kumar 14 25000
3 Bipin Kumar 14 25000
3 Bipin Kumar 14 25000
3 Bipin Kumar 14 25000
3 Bipin Kumar 14 25000
DELETE FROM
TestDup
WHERE
ROWID IN
(SELECT
ROWID
FROM
(SELECT
ROW_NUMBER()
OVER (PARTITION BY id ORDER BY id) rnk
FROM
TestDup)
WHERE
rnk>1
);
output:
ID Name Dept Salary
1 Mukesh Kumar 12 11000
2 Nitin Kumar 13 21000
3 Bipin Kumar 14 25000