xxxxxxxxxx
# IS NULL
SELECT column_names FROM table_name WHERE column_name IS NULL;
# IS NOT NULL
SELECT column_names FROM table_name WHERE column_name IS NOT NULL;
Using 'NULL' and 'NOT NULL'
About `NULL` and `NOT NULL` in SQL, Examples of how to use these conditions in
SQL queries.
xxxxxxxxxx
-- To Check if column contains 'NULL' values, use the 'IS NULL' condition.
-- Example, select all the rows where the column "column_name" is NULL.
-- Query will return all rows where the `column_name` has `NULL` values.
SELECT * FROM table_name WHERE column_name IS NULL;
#-----------------------------------------------------------------------#
-- To check if a column doesn't contain `NULL` values, Use the `IS NOT NULL` condition.
-- Select all rows where the column "column_name" IS NOT NULL.
-- Query will return all rows where `column_name` doesn't have `NULL` values.
SELECT * FROM table_name WHERE column_name IS NOT NULL;
#------------------------------------------------------------------------#
# Combine Example
-- Select rows where "column1" is NULL and "column2" is NOT NULL.
-- Return rows where `column` is `NULL` and `column2` is NOT NULL.
-- Can also combine these condition with other clauses, such as `where`, `AND`, `OR`, etc..
SELECT * FROM table_name
WHERE column1 IS NULL
AND column2 IS NOT NULL;
xxxxxxxxxx
# IS NULL
SELECT column_names FROM table_name WHERE column_name IS NULL;
# IS NOT NULL
SELECT column_names FROM table_name WHERE column_name IS NOT NULL;
xxxxxxxxxx
Tests for empty (NULL) values.
Example: Returns users that haven’t given a contact number.
SELECT * FROM users
WHERE contact_number IS NULL;
xxxxxxxxxx
CREATE TABLE example_table (
id INT NOT NULL,
name VARCHAR(50) NOT NULL,
age INT
);