This is closely related to this question, but adds another requirement.
Given a parent table \'parent\'
╔════════════╦════════╗
║ PARENT_ID ║ NAME
If MySql supported minus
, the query could look like this:
select parent_id
from rel
where prop_id in (5,1)
group by parent_id
having count(distinct prop_id)=2 and count(prop_id)=2
minus
select parent_id
from rel
where prop_id not in (5,1);
The not in
will remove those relationships that exceed (5,1), e.g. (5,1,3).
I know you're using MySql and my answer hence is wrong. Just take it as another idea.