You have to give rownumber for each repeating rows and select duplicate rows by setting condition rn>1
Here is my sample.
CREATE TABLE [dbo].[EMptest](
[EMpCode] [varchar](10) NULL,
[Leave] [varchar](50) NULL,
[Remark] [varchar](100) NULL
)
my insert:
insert into emptest values('May001','CL','Urgent Work')
insert into emptest values('May001','EL','Holiday')
insert into emptest values('May001','CL','Urgent Work')
insert into emptest values('May001','EL','Holiday')
insert into emptest values('May002','CL','Urgent Work')
My query:
WITH CTE AS
(
SELECT *,RN=ROW_NUMBER() OVER (partition by empcode,leave,remark ORDER BY empcode DESC) FROM emptest
)
select a.empcode, a.leave,a.remark from cte a
where a.RN>1
Hemanth.Sutapalli, if this helps please login to Mark As Answer. | Alert Moderator