SELECT Acct.Id, TransactionCode, COUNT (*) as Cnt From Account WHERE Acct.Id NOT IN (SELECT Acct.Id FROM Account WHERE TransactionCode NOT IN ('Code3','Code4') GROUP BY Acct.Id) Group by Acct.Id, TransactionCode