I have the following question:
Find the names of employees who work on all the projects controlled by department number 5.
The tables I have are Employees (SSN), Works_On(SSN, PNumber), Projects(PNumber, DNumber).
I'm trying to figure out the "ALL" part. I tried different methods, but the thing I'm trying to do is create a canonical query tree, so I need to make sure the SQL query can be converted into that.
I've tried the following:
SELECT E.Fname, E.Lname
FROM Employee AS E, works_on AS W
WHERE E.SSN IN ALL
(
SELECT SSN
FROM Projects AS P
WHERE W.SSN = E.SSN AND W.PNUMBER = P.PNUMBER AND P.DNUMBER = 5
);
But I'm unsure it will work since I used IN ALL
. One more thing I tried is getting the count of the works on and group by employee, and getting the count of the projects.
Eventually I found this:
select fname, lname
from employee
where not exists ( (select pnumber from project where dnum = 5)
MINUS
(select pno from works_on where essn = ssn)
);
But I wasn't able to convert it into a tree.
Do you have any suggestions that I might use? And yes it's Homework.