Skip to content Skip to sidebar Skip to footer

Get Either Of The Entry In Duplicate Records

This question is in reference to Get specific entry in case of duplicate entry Now in this scenario the value that is different is user Id and the remaining is same. |UserId | F

Solution 1:

try this !

create table users(UserId int, Firstname varchar(30), Lastname varchar(30), IsRequired varchar(5), IsDeleted varchar(5));

insert into users values('1','harry','tom','true','false');
insert into users values('1','harry','tom','false','false');
insert into users values('3','ram','sham','true','false');

select * from
(
select *,rn=ROW_NUMBER()over(partition by UserId order by Firstname desc) from users
)x
where x.rn=1

See demo


Post a Comment for "Get Either Of The Entry In Duplicate Records"