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
What is a temporal data type?
Which language is used in sql?
How does stored procedure reduce network traffic?
what is datawarehouse? : Sql dba
What is the example of procedure?
What are the different parts of a package?
how to use regular expression in pattern match conditions? : Sql dba
what is difference between delete and truncate commands? : Sql dba
What are the two different parts of the pl/sql packages?
How do I write a cron which will run a sql query and mail the results to agroup?
how to enter binary numbers in sql statements? : Sql dba
define sql update statement ? : Sql dba
What is the best free sql database?
What are different types of queries in sql?
Name the different types of indexes in sql and define them.