MySQL: IS NULL Condition
This MySQL tutorial explains how to use the MySQL IS NULL condition with syntax and examples.
Description
The MySQL IS NULL Condition is used to test for a NULL value in a SELECT, INSERT, UPDATE, or DELETE statement.
Syntax
The syntax for the IS NULL Condition in MySQL is:
expression IS NULL
Parameters or Arguments
- expression
- The value to test if it is 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 MySQL IS NULL in a SELECT statement:
SELECT * FROM contacts WHERE last_name IS NULL;
This MySQL IS NULL example will return all records from the contacts table where the last_name contains a NULL value.
Example - With INSERT Statement
Next, let's look at an example of how to use MySQL IS NULL in an INSERT statement:
INSERT INTO contacts (contact_id, contact_name) SELECT account_no, supplier_name FROM suppliers WHERE category IS NULL;
This MySQL IS NULL example will insert records into the contacts table where the category contains a NULL value.
Example - With UPDATE Statement
Next, let's look at an example of how to use MySQL IS NULL in an UPDATE statement:
UPDATE contacts SET last_name = 'TBD' WHERE last_name IS NULL;
This MySQL IS NULL example will update records in the contacts table where the last_name contains a NULL value.
Example - With DELETE Statement
Next, let's look at an example of how to use MySQL IS NULL in a DELETE statement:
DELETE FROM contacts WHERE last_name IS NULL;
This MySQL IS NULL example will delete all records from the contacts table where the last_name contains a NULL value.
0 comments:
Post a Comment