What are Anti joins

Answer Posted / vivek

Anti-joins:
Anti-joins are written using the NOT EXISTS or NOT IN
constructs. An anti-join between two tables returns rows
from the first table for which there are no corresponding
rows in the second table. In other words, it returns rows
that fail to match the sub-query on the right side.

Suppose you want a list of departments with no employees.
You could write a query like this:
SELECT d.department_name
FROM departments d
MINUS
SELECT d.department_name
FROM departments d, employees e
WHERE d.department_id = e.department_id
ORDER BY department_name;

The above query will give the desired results, but it might
be clearer to write the query using an anti-join:
SELECT d.department_name
FROM departments d
WHERE NOT EXISTS (SELECT NULL
FROM employees e
WHERE e.department_id = d.department_id)
ORDER BY d.department_name;

Is This Answer Correct ?    17 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is an exception in pl/sql?

552


Why we use cross join?

551


How to call a javascript function from pl sql?

577


How do you create a db file?

530


Explain the difference between triggers and constraints?

534






how to delete an existing column in a table? : Sql dba

564


Are subqueries faster than joins?

581


How do you remove duplicates without using distinct in sql?

512


What are different types of statements supported by sql?

626


What is cross join example?

558


Is a secondary key the same as a foreign key?

500


Which function is used to return remainder in a division operator in sql?

593


How to make a copy values from one column to another in sql?

587


Mention what are different methods to trace the pl/sql code?

570


Does sql support programming?

566