We know that when using NOT IN condition on a subquery which has NULL values the query will not produce any results, e.g.:
CREATE TABLE movie ( title TEXT ); INSERT INTO movie (title) VALUES (NULL); INSERT INTO movie (title) VALUES ('ABC'); SELECT * FROM movie WHERE 'Titanic' NOT IN (select title from movie) The query above doesn't return any results.
However if the query is:
SELECT * FROM movie WHERE 'Titanic' NOT IN (title) then the row with title=ABC is returned. Why the queries don't return the same results? Isn't NOT IN condition translated as WHERE 'Titanic' != 'ABC' AND 'Titanic' != NULL in both cases?
in both cases.. no. The last query just uses thetitlevalue from the current row, i.e.'Titanic' NOT IN ('ABC')for that row.'Titanic' NOT IN ('ABC', NULL)?NOT IN (title)here with one field is equivalent to!= title.WHERE 'Titanic' NOT IN (title)is just the same asWHERE 'Titanic' <> title. so for the'ABC'rowNULLdoesn't get involved