Quote:
Originally posted by joseppic
Hi, I have 3 tables, Table Person, Table Skill and Table JoinPersonSkill (many-to-many).
The idea is that a 'Person' can have many 'Skills'.
I would like to do a select where the DB is searched for Persons with
Skill 'A' AND Skill 'B'.
The syntax for the Skill A OR Skill B select is as follows:
select Person.name from Person, Skill, JoinPersonSkill
where
Person.ID = JoinPersonSkill.PersonID
and Skill.ID = JoinPersonSkill.SkillID
and Skill.name = 'A' or Skill.name = 'B' ;
How do I get a Person with Skill A AND Skill B.
Substituting the OR for an AND gives me no results.
Do I need a JOIN condition?
Cheers,
Joseppic.
|
Basically, this query can be written in many ways. one of the way is
select Person.name
from Person, Skill, JoinPersonSkill
where Person.ID=JoinPersonSkill.PersonId
and Skill.ID=JoinPersonSkill.SkillID
and Skill.name='A'
and exists (
select 1
from Skill a , JoinPersonSkill b
where Person.ID=b.PersonId
and a.ID=b.SkillID
and b.name='B'
)