|
Consider 2 projects:
|
Consider the set of employees that work on project 1 and project 2 in relation to the set of employees in the Research
The yellow circle are the employees in the Reseacrh department
The green circle are employees that work on project 1
|
The reddish circle are employees that work on project 2
|
Conclusion:
|
In Psuedo SQL code:
SELECT pname FROM project p WHERE "set of employees working on project p" ⊆ "set of employees in the 'Research' department" |
Re-written solution: SELECT pname FROM project p WHERE "set of employees working on project p" - "set of employees in the 'Research' department" = empty set |
SELECT pname FROM project p WHERE NOT EXISTS (SELECT ssn FROM employee /* Universe set of employee */ WHERE ssn IN "set of employees working on project p" and ssn NOT IN "set of employees in the 'Research' department" ) |
SELECT pname FROM project P WHERE NOT EXISTS (SELECT ssn FROM employee WHERE ssn IN (SELECT essn FROM works_on WHERE pno = P.pnumber) and ssn NOT IN (SELECT ssn FROM employee, department WHERE dno = dnumber AND dname='Research') ) |
|
So these 2 types of queries is very similar !!!
|
We are comparing these 2 set of employees: set1 = { employees working in department "dnumber" } set2 = { employees with one or more dependents } ===> All employees in department "dnumber" are members of set2 |
Re-written solution: SELECT dname FROM department d WHERE "set of employees working in d.dnumber" - "set of employees with one or more dependents" = empty set |
SELECT dname FROM department d WHERE NOT EXISTS (SELECT ssn FROM employee /* Universe set of SSN */ WHERE ssn IN "set of employees working in d.dnumber" and ssn NOT IN "set of employees with one or more dependents" ) |
SELECT dname FROM department d WHERE NOT EXISTS (SELECT ssn FROM employee WHERE ssn IN (SELECT ssn FROM employee WHERE dno = d.dnumber) and ssn NOT IN (SELECT essn FROM dependent) ) |