Helllo I have the following table
In the same sql query
hope this helps
; with cte as ( SELECT ID_2 , COUNT(ID_2) FROM TABLE GROUP BY ID_2 HAVING COUNT(ID_2) = 2 ) SELECT * FROM ( select * from TABLE a join CTE b on a.id_2 = b.id_2 ) where Event_Type = 'M'
This may not be elegant but: SELECT * FROM TABLE WHERE ID_2 IN ( SELECT ID_2 FROM TABLE GROUP BY ID_2 HAVING COUNT(ID_2) = 2 ) AND Event_Type = 'M';