
397 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_nameis the name of the column you want to check forNULLvalues.- If
column_nameisNULL, the condition evaluates toTRUE, and the row is included in the result set. - If
column_nameis 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
emailcolumn isNULL:
SELECT *
FROM customers
WHERE email IS NULL;
- Retrieve products with a
NULLvalue in themanufacturercolumn:
SELECT *
FROM products
WHERE manufacturer IS NULL;
- Find employees with a
NULLvalue in themanager_idcolumn:
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.