IN / NOT IN with Correlated Subquery in Where EXISTS / NOT...

Preview:

Citation preview

IN / NOT IN with Correlated Subquery in Where

EXISTS / NOT EXXISTS with Correlated Subquery

--Retrieve the social security numbers of all employees who work on project

--numbers 1, 2, or 3. --

select distinct essn

from works_on

where pno in (1,2,3);

select distinct essn

from works_on where (pno = 1) OR (pno = 2) OR (pno = 3) ;

select * from employee E

where E.ssn in (select D.essn

from Dependent D);

select *

from employee E where E.ssn in (select D.essn

from Dependent D);

select *

from employee E

where Exists (select D.essn

from Dependent D);

select *

from employee E where Exists (select D.essn

from Dependent D

where E.ssn = D.essn);

select * from employee E

where Not Exists (select D.essn

from Dependent D where E.ssn = D.essn);

select *

from employee E where E.ssn in (select D.mgrssn

from Department D);

select *

from employee E

where E.ssn in (select D.mgrssn

from Department D where E.ssn = D.mgrssn);

select * from employee E, Department D

where E.ssn = D.mgrssn;

Select *

From Employee E

Where E.Dno IN (Select D.Dnumber

From Department D Where E.ssn = D.mgrssn);

select E2.lname, E2.fname from employee E1, employee E2

where E1.superssn = E2.ssn and

E1.dno in (select D.dnumber from Department D, Dependent Dp

where E1.ssn = D.mgrssn and D.mgrssn = Dp.essn);

Select *

From Employee E Where E.Dno IN (Select D.Dnumber

From Department D

Where E.ssn = D.mgrssn);

Select *

From Employee E

Where E.Dno NOT IN (Select D.Dnumber From Department D

Where E.ssn = D.mgrssn);

select *

from employee E

where E.ssn In (select D.mgrssn from Department D)

And

E.ssn Not In (select Dp.essn

from Dependent Dp);

Recommended