I'm guessing this is what you want:-DECLARE @temp table(eno int,eid int)INSERT INTO @temp VALUES (1, 1)INSERT INTO @temp VALUES (2 ,2)INSERT INTO @temp VALUES (3, 3)INSERT INTO @temp VALUES (4, 3)INSERT INTO @temp VALUES (5 ,3)INSERT INTO @temp VALUES (6 ,4)INSERT INTO @temp VALUES (7, 4)INSERT INTO @temp VALUES (8 ,4)INSERT INTO @temp VALUES (9 ,4)INSERT INTO @temp VALUES (10, 5)INSERT INTO @temp VALUES (11, 5)INSERT INTO @temp VALUES (12, 5)select * from @temp SELECT r.eno,r.eidFROM(SELECT ROW_NUMBER() OVER(PARTITION BY t.eid ORDER BY t.eno) AS RowNo,t.eid,t.enoFROM @temp tINNER JOIN (SELECT eid,COUNT(eno) AS empcount FROM @temp GROUP BY eid)tmpON t.eid=tmp.eidWHERE tmp.empcount >1)rWHERE r.RowNo <=2output---------input values:-eno eid----------- -----------1 12 23 34 35 36 47 48 49 410 511 512 5result:-eno eid----------- -----------3 34 36 47 410 511 5