Please help me understand the following from Oracle Introduction to SQL and PL/SQL, Lesson 7 subqueries.
select ename
from emp
where empno NOT IN
(select mgr
from emp);
no rows returned.
Returning Nulls in the Resulting Set of a Subquery
The SQL statement above attempts to display all the employees who do not have any subordinates. Logically, this SQL statement should have returned eight rows. However, the SQL statement does not return any rows. One of the values returned by the inner query is a null value and hence the entire query returns no rows. The reason is that all conditions that compare a null value result in a null. So whenever null values are likely to be part of the resultant set of a subquery, do not use the NOT IN operator.
I read
The reason is that all conditions that compare a null value result in a null...
but the words do not explain... please help me to explain this concept to my students.
thanks MJ
select ename
from emp
where empno NOT IN
(select mgr
from emp);
no rows returned.
Returning Nulls in the Resulting Set of a Subquery
The SQL statement above attempts to display all the employees who do not have any subordinates. Logically, this SQL statement should have returned eight rows. However, the SQL statement does not return any rows. One of the values returned by the inner query is a null value and hence the entire query returns no rows. The reason is that all conditions that compare a null value result in a null. So whenever null values are likely to be part of the resultant set of a subquery, do not use the NOT IN operator.
I read
The reason is that all conditions that compare a null value result in a null...
but the words do not explain... please help me to explain this concept to my students.
thanks MJ