Introduction
We use IS NULL and IS NOT NULL to find out if a value is missing or present in a database column.
SELECT column1, column2 FROM table_name WHERE column_name IS NULL; SELECT column1, column2 FROM table_name WHERE column_name IS NOT NULL;
SELECT * FROM employees WHERE manager_id IS NULL;
SELECT name, email FROM customers WHERE email IS NOT NULL;
SELECT order_id FROM orders WHERE shipped_date IS NULL;
CREATE TABLE students ( id INT, name VARCHAR(50), graduation_year INT ); INSERT INTO students VALUES (1, 'Alice', 2023), (2, 'Bob', NULL), (3, 'Charlie', 2024); SELECT name FROM students WHERE graduation_year IS NULL;
column_name IS NULL check for in a table?IS NULLemail is NOT NULL?IS NOT NULL.orders with columns order_id and shipped_date, what will this query return?SELECT order_id FROM orders WHERE shipped_date IS NULL;
shipped_date IS NULL selects rows where shipped_date is missing.SELECT * FROM employees WHERE manager_id = NULL;
= NULL always returns false because NULL is not equal to anything.IS NULL to check for NULL values properly.IS NULL and IS NOT NULL to do this?SELECT * FROM customers WHERE phone IS NOT NULL AND email IS NULL;
phone IS NOT NULL selects customers who provided a phone number.email IS NULL selects customers who did not provide an email.Pass the test and this pattern moves unknown