![]() |
The In this article, We will learn about the MySQL IS NULL Operator by understanding various examples and so on. MySQL IS NULL Operator
Syntax The IS NULL operator is used in SQL queries to test whether a column value is NULL. The basic syntax for using IS NULL is:
Examples of MySQL IS NULLExample 1: IS NULL with SELECT StatementConsider a table named orders with the following structure:
Inserting sample data into the orders table:
Output: ![]() To retrieve records where the shipping_date is NULL:
Output: ![]() This result shows orders that have not been shipped yet, as their shipping_date is NULL. Example 2: IS NULL with COUNT() FunctionTo count the number of orders that have not been shipped:
Output: ![]() This output indicates that there are 2 orders with a NULL shipping_date. Example 3: IS NULL with UPDATE StatementTo update the shipping_date for orders that have not been shipped yet:
Output: After executing this query, the table orders will be updated. To view the changes, you can run:
Updated Table Data: ![]() This result shows that the shipping_date for the orders with order_id 1 and 3, which previously had NULL values, has been updated to ‘2024-07-10’. Example 4: IS NULL with DELETE StatementTo delete records where the shipping_date is NULL:
After running the delete statement, to view the remaining records:
Output: ![]() This result shows that the orders with NULL shipping_date have been deleted from the table. ConclusionOverall, IS NULL operator is very useful in searching for records in which one or several fields may not have any data. As in this case, the procedures using IS NULL helps in finding the order that has not been shipped. This capability is essential when handling needed data as well as in cases when some operations require the absence or presence of data in certain columns. |
Reffered: https://www.geeksforgeeks.org
Databases |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 20 |