#GoLearningPoint
NULL - Undefined value
This can not be compared with any other values not even with another NULL.
Difference Between Not IN and Not Exists Operator
###NOT IN Operator
The exception is where you have a NULL in the NOT IN subquery.This causes the NOT IN to always be false and
will not return any rows.NOT IN does not have the ability to compare the NULL values.
When using “NOT IN”, the query performs nested full table scans.
###Not Exists Operator
Not Exists is recommended is such cases.
Whereas for “NOT EXISTS”, query can use an index within the sub-query.
Select * From T1
where Col1 NOT IN(Select Col1 From T2 Where Col1 is NOT NULL);
Select * From T1
where Col1 NOT EXISTS(Select Col1 From T2 Where T1.Col1=T2.Col1);
Select * From MyTab;
/* List Employees who are not manager*/
/*Using NOT In*/
Select * From MyTab
Where ID NOT IN(Select MANAGERID From MyTab Where MANAGERID Is NOT NULL);
Select * From MyTab T1
Where NOT EXISTS(Select 1 From MyTab T2 Where T2.MANAGERID=T1.ID);
Ещё видео!