‘Exists’ and ‘not exists’ in Subqueries
SELECT Name
FROM Employee E
WHERE EXISTS
(SELECT *
FROM Dependent D
WHERE E.EmpID = D.EmpID
and E.Sex = D.DepSex)
Which employees have dependents of the same sex as themselves?
Which employees have no dependents?
SELECT Name
FROM Employee E
WHERE NOT EXISTS
(SELECT *
FROM Dependent D
WHERE E.EmpID = D.EmpID)
Previous slide
Back to first slide
View graphic version