Different between NOT IN and NOT EXISTS in postgres SQL

postgresql, sql

Solution

`NOT IN` is true when value is not in the set returned by the subquery. `NOT EXISTS` is true when the subquery doesn't return anything.

Problem

Here's my table. When I execute the below query using NOT IN it gives me namal and Ann. ``` SELECT firstname FROM info.student_info WHERE firstname NOT IN (SELECT firstname FROM info.student_info WHERE lastname IS NULL) ``` But when I execute the below query using NOT EXISTS it gives me no rows. ``` SELECT firstname FROM info.student_info WHERE NOT EXISTS (SELECT firstname FROM info.student_info WHERE lastname IS NULL) ``` Why is this? I have researched some areas on NOT IN and NOT EXISTS, but couldn't find an answer for this.

Original source