SQL

 

1. Fetch Duplicate Entries in a Table 


Create table tempusers

(

userid int primary key,

username varchar(30) not null,

email varchar(50));


insert into tempusers values

(1, 'Sumit', 'sumit@gmail.com'),

(2, 'Reshma', 'reshma@gmail.com'),

(3, 'Farhana', 'farhana@gmail.com'),

(4, 'Robin', 'robin@gmail.com'),

(5, 'Robin', 'robin@gmail.com');


select * from tempusers;


Result: 



Query - for finding duplicate entry:

select userid, username, email
from (
select *,
row_number() over (partition by username order by userid) as rn
from tempusers u) x
where x.rn <> 1;









Comments