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
Is left join faster than inner join?
Do prepared statements prevent sql injection?
What is function and procedure in pl sql?
What is difference between sql and excel?
How do I create an index in word?
What are the two types of exceptions.
how can we submit a form without a submit button? : Sql dba
Are sql database names case sensitive?
Can two tables have same primary key?
what is try_catch block in procedure
How do you pronounce sql?
Does execute immediate commit?
What is dbo in sql?
What are different types of statements supported by sql?
What is the difference between inner join and natural join?