Myslím, že tento dotaz by vám pomohl:
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
Vrátí id_wc = 1
.
Pro (6, 3) dotaz nevrací nic.