SQL Practice Logo

SQLPractice Online

Advanced NOT & Negation Logic: Mistakes

Module: Advanced Filtering

SELECT * FROM products WHERE id NOT IN (SELECT product_id FROM discontinued);

SELECT * FROM products p WHERE NOT EXISTS (SELECT 1 FROM discontinued d WHERE d.product_id = p.id);

If discontinued.product_id has any NULL, NOT IN returns no rows. Use NOT EXISTS for NULL-safe negation.

Always use NOT EXISTS instead of NOT IN for subqueries

High

NOT IN fails if subquery contains NULL

SELECT * FROM customers WHERE NOT NOT status = 'active';

SELECT * FROM customers WHERE status = 'active';

NOT NOT cancels out but is hard to read. Simplify to positive condition.

Avoid double negatives, use positive logic

Medium

Double negative is confusing