このクエリはあなたに役立つと思います:
SET @tag1 = 1, @tag2 = 4; -- Setting some user variables to see where the ids go. (you can put the values in the query)
SELECT wtagrels.id_wc,
SUM(DISTINCT( wtagrels.id_tag [email protected] OR wtagrels.id_tutor [email protected])) AS key_1_total_matches,
SUM(DISTINCT( wtagrels.id_tag [email protected] OR wtagrels.id_tutor [email protected])) AS key_2_total_matches
FROM all_tag_relations AS wtagrels
WHERE ( wtagrels.id_tag [email protected] OR wtagrels.id_tag [email protected] )
GROUP BY wtagrels.id_wc
HAVING key_1_total_matches = 1 AND key_2_total_matches = 1
LIMIT 0, 20
id_wc = 1
を返します 。
(6、3)の場合、クエリは何も返しません。