This SQL tutorial explains how to use the SQL IS NULL condition with syntax and examples.
DESCRIPTION
The SQL IS NULL condition is used to test for a NULL value in a SELECT, INSERT, UPDATE, or DELETE statement.
SYNTAX
The syntax for the SQL IS NULL condition is:
expression IS NULL
Parameters or Arguments
- expression
- The expression to test for a NULL value.
NOTE
- If expression is a NULL value, the condition evaluates to TRUE.
- If expression is not a NULL value, the condition evaluates to FALSE.
EXAMPLE - WITH SELECT STATEMENT
Let's look at an example of how to use IS NULL in a SELECT statement:
SELECT * FROM suppliers WHERE supplier_name IS NULL;
This SQL IS NULL example will return all records from the suppliers table where the supplier_name contains a NULL value.
EXAMPLE - WITH INSERT STATEMENT
Next, let's look at an example of how to use SQL IS NULL in an INSERT statement:
INSERT INTO suppliers (supplier_id, supplier_name) SELECT account_no, name FROM customers WHERE city IS NULL;
This SQL IS NULL example will insert records into the suppliers table where the city contains a NULL value.
EXAMPLE - WITH UPDATE STATEMENT
Next, let's look at an example of how to use SQL IS NULL in an UPDATE statement:
UPDATE suppliers SET supplier_name = 'Apple' WHERE supplier_name IS NULL;
This SQL IS NULL example will update records in the suppliers table where the supplier_name contains a NULL value.
EXAMPLE - WITH DELETE STATEMENT
Next, let's look at an example of how to use SQL IS NULL in a DELETE statement:
DELETE FROM suppliers WHERE supplier_name IS NULL;
This SQL IS NULL example will delete all records from the suppliers table where the supplier_name contains a NULL value
No comments:
Post a Comment