select * from (select e.* , count(*) over (partition by e.id) as cnt from dbo.EMP e join dbo.HREMP aon a.ID = e.ID join dbo.LOGO c on c.EMPID = e.id join dbo.LOGOACC d on d.BADGENO = c.BADGENOand d.ACCLVID in (2191, 2292, 2293, 2294, 2295, 2296, 2297) ) tt where tt.cnt > 1



