-- Lösning 1:
select t1.PeopleID, t1.WantedSetID
from (
select pa.PeopleID, wa.WantedSetID,
ROW_NUMBER() over (partition by pa.PeopleID, wa.WantedSetID order by PeopleAttributeID) as rownbr
from PeopleAttribute pa
join WantedAttribute wa on pa.AttributeID = wa.AttributeID
and pa.AttributeValue = wa.AttributeValue
) t1 join (
select WantedSetID,
ROW_NUMBER() over (partition by WantedSetID order by WantedAttributeID) as rownbr
from WantedAttribute
) t2 on t1.WantedSetID = t2.WantedSetID
group by t1.PeopleID, t1.WantedSetID
having max(t1.rownbr) = max(t2.rownbr)
-- Lösning 2:
select t1.PeopleID, t1.WantedSetID
from (
select pa.PeopleID, wa.WantedSetID, COUNT(*) AS cnt
from PeopleAttribute pa
join WantedAttribute wa on pa.AttributeID = wa.AttributeID
and pa.AttributeValue = wa.AttributeValue
group by pa.PeopleID, wa.WantedSetID
) t1 join (
select WantedSetID, Count(*) as cnt
from WantedAttribute
group by WantedSetID
) t2 on t1.WantedSetID = t2.WantedSetID and t1.cnt = t2.cnt