Created
September 18, 2015 13:00
-
-
Save robertscherer/f7140483143f6af8cc3e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT s.* FROM services s | |
INNER JOIN ( | |
SELECT st.service_id FROM services_typetags st | |
INNER JOIN services s ON s.id = st.service_id | |
INNER JOIN typetags t ON t.id = st.typetag_id | |
WHERE t.id IN (8, 9, 11) | |
GROUP BY st.service_id | |
HAVING COUNT(st.service_id) = 3 | |
) ss | |
ON s.id = ss.service_id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here we want to filter using the services_typetags n:m relation and have all services returned, which have at least the typetags 8, 9 and 11.