Doing an 'AND' select on a two field table
Posted by:
Rob Lee
Date: June 14, 2005 06:34AM
How can I select rows from a table that match a series of conditions:
My table is like this:
char_voice_id, voice_id, attr_id
1,1,1
2,1,2
3,1,3
4,2,4
5,2,7
6,3,1
7,3,2
8,3,3
I want to select the rows where the attr_id matches, say, two or more values. For example, I want attr_id =1, 2 and 3. Which means I want voice_id 1 and 3 returned. Get it?
The 'AND' operator in the Select statement returns nothing... ie.
SELECT voice_id, attr_id FROM char_voice WHERE (attr_id = 1 AND attr_id = 2 AND attr_id = 3)
and I can see why...
'OR' returns those that match any where clause.
Do I need to a recursive 'in_array', or is there a clever way to use, for example, 'array_intersect_assoc'
Thanks, and sorry for the mundaneness... any feedback welcome.
Rob