How NOT IN works with NULL values.

Recently I faced one scenario with NULL value with NOT IN, I have added the details here about what I learnt. suppose we have two table Category and Product id | name -------- 1 | CAT1 2 | CAT2 3 | CAT3 4 | CAT4 Product id | name | category_id ----------------------------- 1 | PR1 | 1 2 | PR2 | 2 3 | PR3 | 2 4 | PR4 | 3 5 | PR5 | 4 6 | PR6 | NULL Scenario :- *I just want to retrieve all the Products excluding Category CAT1 and CAT3 so I wrote following query :- Product.joins(:category).where("categories.name NOT IN (?)", ['CAT1', 'CAT3']) it gives following