Introduction
We use WHERE with IS NULL or IS NOT NULL to find rows where a column has no value or does have a value. This helps us filter data based on missing or existing information.
SELECT column1, column2 FROM table_name WHERE column_name IS NULL; SELECT column1, column2 FROM table_name WHERE column_name IS NOT NULL;
SELECT name FROM employees WHERE manager_id IS NULL;
SELECT order_id FROM orders WHERE delivery_date IS NOT NULL;
SELECT product_name FROM products WHERE discount IS NULL;
CREATE TABLE customers ( id INT, name VARCHAR(50), phone VARCHAR(20) ); INSERT INTO customers (id, name, phone) VALUES (1, 'Alice', '123-4567'), (2, 'Bob', NULL), (3, 'Charlie', '987-6543'), (4, 'Diana', NULL); -- Find customers without phone number SELECT name FROM customers WHERE phone IS NULL; -- Find customers with phone number SELECT name FROM customers WHERE phone IS NOT NULL;
email column has no value stored (is missing)?IS NULL, not = NULL or empty string.phone column is NOT missing?IS NOT NULL to find rows where value exists.employees with columns id, name, and manager_id where some employees have no manager (NULL), what will this query return?SELECT name FROM employees WHERE manager_id IS NULL;
manager_id IS NULL filters rows where manager_id has no value (missing).address is NOT NULL:SELECT * FROM customers WHERE address != NULL;
IS NOT NULL to check for non-missing values.orders with columns order_id, customer_id, and shipped_date. Some orders are not shipped yet and have shipped_date as NULL. Which query lists all orders that have been shipped?IS NOT NULL to find rows where shipped_date has a value.Pass the test and this pattern moves unknown