I have a table emp_skills which has emp_id and skill_id as two columns. Now,
SELECT * FROM emp_skills where skill_id REGEXP '^[2,3]$'
outputs emp_id’s of those who have either 2 or 3 or both. What I want is emp_id’s of those which have both 2 and 3 as their skill_id’s. Skill_id is Integer
Example output of above query
EMP_ID SKILL_ID
401 2
405 2
401 3
405 3
407 3
Now what is I want is only first four rows as 407 does not have 2 as skill_id
from your phrase
both 2 and 3 as their skill_id, i think you don’t needregexfor this. All you need are onlycount,group byandhavingyou need to match the number of records with the total number of id supplied in the
whereclause.SQLFiddle Demo