6. MICROSOFT ACCESS QUERIES – ADVANCED
6.8.5: Anti-Join
Suppose we need to list persons in our Company database that are not supervising anyone. One way of looking at this problem is to say we need to find those people that do not join to someone else based on the supervises relationship. That is, we need to find those employees whose employee id does not appear in the supervisor field of any employee.
To do this with MS Access, we can construct a query that uses an outer join to connect an employee to another employee based on employeeID equaling supervisor, but where the supervisor value is null. That is, we are looking for an employee who, in an outer join, does not join to another employee. See the query below:
This query involves a join, specifically an outer join, and because it retrieves that rows that do not join, it is sometimes referred to as a special case – an anti-join.
Exercises
1) Consider the Company database and develop a query to count the number of employees who do not supervise anyone.
2) Consider the Library database. Create a query to list books that no one borrowed.
3) Consider the Library database. Create a query to list members that have not borrowed a book.