edited by
2,525 views
2 votes
2 votes

Question- Retrieve the name of each employee who works on all the projects controlled by department number 5???

SELECT Lname, Fname FROM EMPLOYEE WHERE NOT EXISTS ( SELECT * FROM WORKS_ON B WHERE ( B.Pno IN ( SELECT Pnumber FROM PROJECT WHERE Dnum=5 ) AND NOT EXISTS ( SELECT * FROM WORKS_ON C WHERE C.Essn=Ssn AND C.Pno=B.Pno )));

Can someone plz explain how this query works?? please?? This query is on page number 270 nawathe book.

edited by

1 Answer

2 votes
2 votes

You can go through it actually first inner subquery is non correlated means you can execute it one time and leave it but second inner subquery is correlated means for each row in employee table you have to go through works on table and see that whether particular employee is working on that project or not as you can see employee a works on all project of dept 5 so inner subquery result will be null and hence not exist returns true so a will be printed

And employee b not working on any project controlled by dept no. 5 so inner subquery return 25 so not exist return false so that particular b will not be printed

 

No related questions found