
226 views
MySQL IS NULL
The MySQL IS NULL
condition is used to check whether a column contains a NULL
value. It is often used in the WHERE
clause of a SQL query to filter rows where a particular column is NULL
. The IS NULL
condition returns TRUE
for rows that have a NULL
value in the specified column and FALSE
for rows with non-NULL
values.
The basic syntax of the IS NULL
condition is as follows:
SELECT columns
FROM table
WHERE column_name IS NULL;
Here’s how it works:
column_name
is the name of the column you want to check forNULL
values.- If
column_name
isNULL
, the condition evaluates toTRUE
, and the row is included in the result set. - If
column_name
is notNULL
, the condition evaluates toFALSE
, and the row is excluded from the result set.
Here are some examples to illustrate the use of the IS NULL
condition:
- Match all records where the
email
column isNULL
:
SELECT *
FROM customers
WHERE email IS NULL;
- Retrieve products with a
NULL
value in themanufacturer
column:
SELECT *
FROM products
WHERE manufacturer IS NULL;
- Find employees with a
NULL
value in themanager_id
column:
SELECT *
FROM employees
WHERE manager_id IS NULL;
The IS NULL
condition is a useful tool when you want to filter rows based on the presence or absence of NULL
values in a specific column. It allows you to identify and handle data where values are missing or undefined.