SQL Select only rows where exact multiple relationships exist
This alternative has the benefit of a constant statement structure and only one parameter, independent of the amount of relations you are looking for:
SELECT parent_id FROM rel GROUP BY parent_id HAVING GROUP_CONCAT(prop_id ORDER BY prop_id ASC SEPARATOR ",") = '1,5';
- You need to prepare an ordered, comma separated String of prop_ids upfront.
- This works on MySQL, but not all database servers.