
338 views
MySQL IS NOT NULL
The MySQL IS NOT NULL condition is used to check whether a column contains a non-null value. It is often used in the WHERE clause of a SQL query to filter rows where a particular column is not null. The IS NOT NULL condition returns TRUE for rows that have a non-null value in the specified column and FALSE for rows with null values.
The basic syntax of the IS NOT NULL condition is as follows:
SELECT columns
FROM table
WHERE column_name IS NOT NULL;
Here’s how it works:
column_nameis the name of the column you want to check for non-null values.- If
column_nameis not null, the condition evaluates toTRUE, and the row is included in the result set. - If
column_nameis null, the condition evaluates toFALSE, and the row is excluded from the result set.
Here are some examples to illustrate the use of the IS NOT NULL condition:
- Match all records where the
emailcolumn is not null:
SELECT *
FROM customers
WHERE email IS NOT NULL;
- Retrieve products with a non-null value in the
manufacturercolumn:
SELECT *
FROM products
WHERE manufacturer IS NOT NULL;
- Find employees with a non-null value in the
manager_idcolumn:
SELECT *
FROM employees
WHERE manager_id IS NOT NULL;
The IS NOT NULL condition is a useful tool when you want to filter rows based on the presence or absence of non-null values in a specific column. It is often used in combination with other conditions to build more complex queries.