Du skal bruge en kombination af IN()
og GROUP BY ... HAVING
at opnå dette. Det er heller ikke nødvendigt at deltage, hvis alt hvad du behøver er bruger-id'er. Så noget i stil med:
SELECT user, COUNT(attribute) AS attribute_count
FROM attributes
WHERE attribute IN(...) /* include your set of attributes here */
GROUP BY user
HAVING attribute_count = ? /* include number equal to number of attribute ID's in IN() above */
Hvis du har brug for bruger-id'er og navne, kan du blot tilslutte dette postsæt afledt af forespørgslen ovenfor som et filter til brugertabellen:
SELECT user.id, user.name
FROM user
INNER JOIN
(
SELECT user, COUNT(attribute) AS attribute_count
FROM attributes
WHERE attribute IN(...) /* include your set of attributes here */
GROUP BY user
HAVING attribute_count = ? /* include number equal to number of attribute ID's in IN() above */
) AS filter
ON user.id = filter.user