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

How do I run a sql query in pgadmin 4?

541


What is the difference between microsoft access and sql server?

525


What is the difference between function and procedure in pl/sql?

531


What is Histogram?

1095


Explian rowid, rownum?

556






what are the differences between procedure-oriented languages and object-oriented languages? : Sql dba

500


What is database sql?

537


What is data type in sql?

550


What are aggregate and scalar functions?

520


What are tables in sql?

541


What does desc stand for?

584


Is and as keyword in pl sql?

509


What does fetching a cursor do?

610


How do I run a sql script?

510


How do I run pl sql in sql developer?

621