I would like to complicate this request by changing the scenario. Here is the link to the original request. Here is the link to the original request.
I have the following MySQL table called skills.
id | idUser | idSkill |
---|---|---|
1 | 4 | 1 |
2 | 8 | 4 |
3 | 8 | 9 |
4 | 13 | 9 |
5 | 18 | 2 |
6 | 22 | 1 |
7 | 27 | 2 |
8 | 32 | 4 |
9 | 11 | 2 |
10 | 32 | 9 |
10 | 32 | 7 |
I need to select, for example, all idUsers that have idSkill 4 and 9 at the same time (mandatory skills).
But I would like to have the possibility to search by optional idSkills (if any).
Mandatory skills are 9 and 4
Optional skill is 7
The result would be idUser 32.
I thought of this query:
SELECT id, idUser, idSkill FROM skills WHERE idSkill IN (9,4,7) GROUP BY idUser HAVING (idSkill IN (9,4))
But it clearly does not work.
Many thanks