The original question is the following:
Where A=1 AND A=2 returns 0 row problem – (Short Mysql question)
Thanks for some helpful answers. (but soon I realized I may have over-simplified the problem)
Actually the real problem is the following:
Tag 1,2,3 - category A
Tag 4,5,6 - category B
Tag 7,8,9 - category C
I want to achieve “OR condition” for the same category but “AND condition” for different category.
So I may want to return something like
-- I want id with Tag 1,4 or 1,2,4 but not 4
SELECT id FROM table WHERE Tag IN (1,2) AND Tag (4)
-- Tag 1,4 or 1,5 but not 1
SELECT id FROM table WHERE Tag IN (1) AND Tag (4,5)
-- Only Tag 1,4,9
SELECT id FROM table WHERE Tag IN (1) AND Tag (4) AND Tag (9)
I am trying to figure out from the answers, but any quick guide would be appreciated!
From my understanding you want to return ids that are tagged over at least 2 different categroies, try this: