• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

SQL Query help

KB

Diamond Member
Three Tables

Person
------------
PersonID
Name


PersonSkills
------------
PersonSkillID
PersonFK -------> Person.PersonID
SkillFK ------> Skills.SkillID



Skills
------------
SkillID
SkillName



I am trying to query for all people who have SkillID 1, 4 and 5. They must have all 3 skills, not just one of the Skills. So WHERE SKILLID IN (1,4,5) isn't going to work.
WHERE SKILLID = 1 AND SKILLID = 4 AND SKILLID = 5 doesn't work either.


 
SELECT *
FROM Person
WHERE EXISTS (SELECT 1 FROM PersonSkills WHERE PersonID = Person.PersonID AND SkillID = 1)
AND EXISTS (SELECT 1 FROM PersonSkills WHERE PersonID = Person.PersonID AND SkillID = 4)
AND EXISTS (SELECT 1 FROM PersonSkills WHERE PersonID = Person.PersonID AND SkillID = 5)
 
SELECT PersonSkills.PersonFK, Count(PersonSkills.PersonFK) AS CountOfPersonFK
FROM PersonSkills
WHERE (((PersonSkills.SkillFK) In (1,4,5)))
GROUP BY PersonSkills.PersonFK
HAVING (((Count(PersonSkills.PersonFK))=3));

Access query. 😛
 
Back
Top