Rob Lee wrote:
> 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?
One way:
SELECT
voice_id
FROM char_voice
WHERE
attr_id IN (1,2,3)
GROUP BY voice_id
HAVING COUNT(*) = 3; # 3 = number of distinct attr_id's in IN-list
This method relies on a UNIQUE constraint for (voice_id, attr_id).
--
felix
Please use
BBCode to format your messages in this forum.