In SQL, why does the expression column = NULL not return rows where column is NULL?
Think about what NULL means in SQL and how comparisons work with unknown values.
In SQL, NULL means unknown or missing data. Comparing anything to NULL with '=' does not return true or false but unknown, so no rows match. To check for NULL, use IS NULL.
Given a table users with a column email that contains some NULL values, what rows will this query return?
SELECT * FROM users WHERE email = NULL;
Remember how '=' works with NULL in SQL.
The condition email = NULL always evaluates to unknown, so no rows satisfy it. To find NULLs, use email IS NULL.
Choose the SQL query that correctly returns rows where the status column is NULL.
Think about the special syntax for NULL comparisons in SQL.
Only IS NULL correctly checks for NULL values. '=' and '==' do not work with NULL, and '!=' also does not find NULLs.
Consider performance and correctness. Why should you use IS NULL instead of = NULL in SQL WHERE clauses?
Think about how the database engine treats NULL comparisons internally.
'IS NULL' is the correct and optimized way to check for NULLs. '= NULL' never matches and can cause inefficient scans or confusion.
Given a table products with a nullable column discount, what happens when running this query?
SELECT * FROM products WHERE discount = NULL;
Recall how NULL comparisons behave in SQL.
Comparing with '=' to NULL always yields unknown, so no rows match. No syntax error occurs.