Q&A for anime and manga fans
-- Enter Query Title -- Enter Query Description declare @T table ( [key] char(4), code int, primary key([key], code) ) insert into @T values ('key1', 220), ('key1', 221), ('key2', 220), ('key2', 221), ('key2', 222), ('key3', 220), ('key3', 333), ('key4', 255), ('key5', 220), ('key5', 221) declare @Match table (code int) insert into @Match values (220),(221) select T.[key] from @T as T left outer join @Match as M on T.code = M.code group by T.[key] having count(*) = (select count(*) from @Match) and count(M.code) = (select count(*) from @Match)