Query: mutually exclusive union
Posted: Wed Apr 03, 2013 4:13 pm
my table looks like something like:
id | tag_id
1 | 1
2 | 2
3 | 3
1 | 2
I need a query that only grabs the id where it has all of the tag ids in the condition:
select * from table where tag_id = 1 and tag_id = 2
The above query doesn't work. I would expect ID of 1 to be returned.
I'v tried an OR but that includes results that do not have ALL of the tag_ids (1, 2) (just like OR states).
id | tag_id
1 | 1
2 | 2
3 | 3
1 | 2
I need a query that only grabs the id where it has all of the tag ids in the condition:
select * from table where tag_id = 1 and tag_id = 2
The above query doesn't work. I would expect ID of 1 to be returned.
I'v tried an OR but that includes results that do not have ALL of the tag_ids (1, 2) (just like OR states).