Get count of intersected rows on the same table I have the following table:

ID  user_id          skill_id        
1   8                1    
2   8                3     
3   2                3        
4   5                3          
5   2                1          
6   5                2
7   5                4
8   5                5
9   8                5   


I need to get the count of users who have both skills 1 and 3 (or more), a real life example would be to get the count of users who know php,mysql,and javascript, but not those that only know php and javascript.

When I do SELECT COUNT(USER_ID) WHERE skill_id IN(1,3) I get a count of 3, which means it's giving me the users with any of them, I need the users who have all?

As a side note I think I could do this intersecting different queries but that would mean a separated query for each tag and there can be endless combinations of skills, something tells me there is a simpler way, speed is really important here.

Thanks.
To obtain those users use

SELECT user_id
FROM `table`
WHERE skill_id IN(1,3)
GROUP BY user_id
HAVING 2 = COUNT(*) 


If there is no unique constraint for (user_id, skill_id), use COUNT (DISTINCT skill_id) instead of COUNT(*).

To obtain only the count of those users you may use the above query as a subquery:

SELECT COUNT(*)
FROM ( SELECT user_id
       FROM `table`
       WHERE skill_id IN(1,3)
       GROUP BY user_id
       HAVING 2 = COUNT(*) 
     ) AS `table`