I have three tables
Employee
SSN Name
1 a
2 b
3 c
Projects
Pno Name
1 x
2 y
3 z
Works_On
ESSN Pno
1 1
1 2
2 1
3 1
3 2
3 3
Okay so the question is, how do I know (by query) which employee works on ALL projects. I cant seem to compare multi with multi.
Thank you and sorry for a silly question.
One way to do it is to count all projects, count number of projects for employee and then select all employees that work on the same number of projects:
ProjectCountvariable is there to skip counting projects for every employee.UPDATE: How it works:
For each employee count how many records are in
Works_Ontable with fieldESSNequal to current employee’sSSNand then compare that number to total number of projects.Query:
will give you total number of records in
Works_Ontable (6 in your case). We want to count how many records are there for each employee and that’s why we embedded that query in our main query with condition to select only records fromWorks_Ontable that have current employee’sSSN. If you had to write this in some programming language, this would be logically equivalent toforeachloop on employees collection where in body of the loop you select all records fromWorks_Ontable for current employee and then compare it with total number of projects. If current employee has number of projects equal to the total number of projects, count it.I hope this helps.