Hi guys
I'm having a little trouble with a query that needs to return only the rows that meet all criteria.
The table I have basically contains 2 columns 'productId' and 'value'
Now if I have 7 rows:-
4 rows with productId = prod1 and value = 1,2,3 and 4.
3 rows with productId = prod2 and value = 1,3,4 and 5.
I want to be able to search for all productId where value = 2 or 3 but only return prod1 because only prod1 has rows with values of 2 and 3.
If I use AND I get no results because value = 2 AND value = 3 isn't actually correct, if I use IN (or OR) something like IN(2,3) I get both prod1 and prod2 back because I'm saying 'rows with 2 or 3 in them'.
What I need is something like an exclusive or that only returns the row(s) that meet all OR criteria .
I hope this makes sense.
K
-------------------------------------------------
Note:
Just to not that I think I've found a solution but it's a bit messy, so is there a tidy way of doing this? :-
SELECT * FROM filters AS t1 WHERE t1.type='PROD_SIZE' AND t1.value = 3
AND (SELECT s1.product_id FROM filters AS s1 WHERE s1.type = t1.type AND s1.product_id = t1.product_id AND s1.value = 4)