- SQL - Discussion
- SQL - Useful Resources
- SQL - Useful Functions
- SQL - Quick Guide
- SQL - Questions and Answers
- SQL - Datatype Functions
- SQL - Conversion Functions
- SQL - JSON Functions
- SQL - Cursor Functions
- SQL - Logical Functions
- SQL - Statistical Functions
- SQL - Text & Image Functions
- SQL - Numeric Functions
- SQL - Aggregate Functions
- SQL - String Functions
- SQL - Date Functions
- SQL - Database Tuning
- SQL - IN vs EXISTS
- SQL - Group By vs Order By
- SQL - Common Table Expression
- SQL - Cursors
- SQL - Date & Time
- SQL - Auto Increment
- SQL - Using Sequences
- SQL - Handling Duplicates
- SQL - Sub Queries
- SQL - Transactions
- SQL - NULL Values
- SQL - Stored Procedures
- SQL - Default Constraint
- SQL - Check Constraint
- SQL - Null Functions
- SQL - Min & Max
- SQL - Hosting
- SQL - Injection
- SQL - Comments
- SQL - Wildcards
- SQL - Non-Clustered Index
- SQL - Clustered Index
- SQL - Unique Index
- SQL - Primary Key
- - 工会诉Join
- SQL - Inner Join
- SQL - Using Joins
- SQL - Aliases
- SQL - EXCEPT Operator
- SQL - INTERSECT Operator
- SQL - UNION vs UNION ALL
- SQL - UNION Operator
- SQL - BETWEEN Operator
- SQL - NOT NULL
- SQL - IS NOT NULL
- SQL - IS NULL
- SQL - NOT EQUAL
- SQL - NOT Operator
- SQL - CASE
- SQL - EXISTS Operator
- SQL - ANY, ALL Operators
- SQL - IN Operator
- SQL - LIKE Operator
- SQL - BOOLEAN (BIT) Operator
- SQL - AND & OR
- SQL - Having Clause
- SQL - Group By Clause
- SQL - Order By Clause
- SQL - Distinct Clause
- SQL - Top Clause
- SQL - Where Clause
- SQL - Rename Views
- SQL - Drop Views
- SQL - Update Views
- SQL - Create Views
- SQL - Sorting Results
- SQL - Delete Query
- SQL - Update Query
- SQL - Insert Into Select
- SQL - Select Into
- SQL - Select Query
- SQL - Insert Query
- SQL - Constraints
- SQL - Delete Table
- SQL - Drop Table
- SQL - Alter Tables
- SQL - Temporary Tables
- SQL - Clone Tables
- SQL - Truncate Table
- SQL - Rename Table
- SQL - Show Tables
- SQL - Create Table
- SQL - Backup Database
- SQL - Show Database
- SQL - Rename Database
- SQL - Select Database
- SQL - Drop Database
- SQL - Create Database
- SQL - Expressions
- SQL - Operators
- SQL - Data Types
- SQL - Syntax
- SQL - Databases
- SQL - RDBMS Concepts
- SQL - Overview
- SQL - Home
5. 图瓦卢
- 页: 1
- 页: 1
- 结构-创建指数
- 页: 1
- 页: 1
- 页: 1
- SQL - Foreign Key
- 文 件
- ∗ E/CN.6/2009/1。
- 页: 1
- 页: 1
- 文 件
- 页: 1
- 页: 1
- 文 件
- 页: 1
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
SQL - IS NULL
The "IS NULL" operator in SQL is used to check if a column has a NULL value. It returns true if the column value is NULL and false if it is not.
A field with a NULL value denotes that it has no value. It is possible to create a new record or update an existing record without providing a value for a field in a table. If we do so, the field will then be saved with the value NULL.
Comparison operators pke =, <, or <> cannot be used to check for NULL values. Instead, we use the following operators.
Is null
Is not null (negation of NULL values)
Null value in SQL
SQL does not permit leaving any field of a column without value. logically, table columns without values are empty fields. In reapty, fields having an unspecified value are regarded as NULL. When we don t enter anything into a table cell, SQL assumes that there is a value that, at this time, is unknown but might one day be known and placed in this field.
Syntax
Following is the syntax for null value −
SELECT column_name1, column_name2, column_name3, ... , column_nameN FROM table_name WHERE column_nameN = NULL
The IS NULL Operator
SQL IS NULL is a logical operator that enables you to filter out rows with missing data from your results. Null values, or cells without any data, can appear in some tables. IS NULL allows you to choose rows in a given column that are empty.
Syntax
Following is the syntax for IS NULL −
SELECT column_name1, column_name2, column_name3, ... , column_nameN FROM table_name WHERE column_nameN IS NULL
Example
Let’s consider a table named "Fruit" that we are going to create in our database and which contains some null values in the fields. Execute the below query to create a table.
SQL> CREATE TABLE Fruit ( ID INT NOT NULL, NAME VARCHAR (20) NOT NULL, ADDRESS CHAR (25), PRICE DECIMAL (18, 2), PRIMARY KEY (ID) );
Now we are going to populate the above-created table by using the below query.
SQL> INSERT INTO Fruit (ID,NAME,ADDRESS,PRICE) VALUES (1, Apple , Shimla , 2000.00 ); INSERT INTO Fruit (ID,NAME,ADDRESS,PRICE) VALUES (2, Mango ,NULL, 3000.00 ); INSERT INTO Fruit (ID,NAME,ADDRESS,PRICE) VALUES (3, Orange ,NULL, 4000.00 ); INSERT INTO Fruit (ID,NAME,ADDRESS,PRICE) VALUES (4, Banana , AP ,NULL); INSERT INTO Fruit (ID,NAME,ADDRESS,PRICE) VALUES (5, JackFruit , Ooty ,NULL);
Verification
To check whether the table is created or not, let’s execute the below query.
SQL> SELECT * FROM Fruit;
On executing it, it will display a table as shown below −
+----+-----------+---------+---------+ | ID | NAME | ADDRESS | PRICE | +----+-----------+---------+---------+ | 1 | Apple | Shimla | 2000.00 | | 2 | Mango | NULL | 3000.00 | | 3 | Orange | NULL | 4000.00 | | 4 | Banana | AP | NULL | | 5 | JackFruit | Ooty | NULL | +----+-----------+---------+---------+
IS NULL with SELECT statement
We can use IS NULL operator with a SELECT statement to filter rows based on whether a particular column contains a NULL value or not.
Example
In the following query, we are going to show how the IS NULL condition is going to be used to select rows if the specified field is NULL.
SQL> SELECT * FROM Fruit WHERE ADDRESS IS NULL;
Output
On executing the above query, it will generate an output as shown below −
+----+--------+---------+---------+ | ID | NAME | ADDRESS | PRICE | +----+--------+---------+---------+ | 2 | Mango | NULL | 3000.00 | | 3 | Orange | NULL | 4000.00 | +----+--------+---------+---------+
IS NULL with COUNT() function
We can also use the IS NULL operator with the COUNT() function in SQL to count the number of rows that contain NULL values in a particular column. This function is utipzed along with the SQL SELECT command.
Syntax
Following is the syntax for COUNT() function −
SELECT COUNT(column_name) FROM table_name WHERE condition;
Example
The following query determines the count of rows have a blank field (NULL) in Price column.
SQL> SELECT COUNT(*) FROM Fruit WHERE PRICE IS NULL;
Output
On executing the above query, it will generate an output as shown below −
+----------+ | COUNT(*) | +----------+ | 2 | +----------+
IS NULL with UPDATE statement
We can use the UPDATE statement with the "IS NULL" operator in SQL to set the value of a column to NULL for all rows that meet a certain condition.
Example
Consider the following table "fruit" in our database and run the following query to see how the update statement is used.
SQL> UPDATE Fruit SET PRICE= 1000 WHERE PRICE IS NULL;
Verification
To check whether the table has been updated or not, execute the below query.
SQL> SELECT * FROM Fruit;
On executing the above query, it will generate the following output as shown below −
+----+-----------+---------+---------+ | ID | NAME | ADDRESS | PRICE | +----+-----------+---------+---------+ | 1 | Apple | Shimla | 2000.00 | | 2 | Mango | NULL | 3000.00 | | 3 | Orange | NULL | 4000.00 | | 4 | Banana | AP | 1000.00 | | 5 | JackFruit | Ooty | 1000.00 | +----+-----------+---------+---------+
SQL IS NULL with DELETE statement
We can also use the DELETE statement with IS NULL operator to delete all rows that contain NULL values in a particular column.
Example
Execute the below query to observe how we are going to use the delete statement with is null.
SQL> DELETE FROM Fruit WHERE ADDRESS IS NULL;
Verification
Execute the below query to check whether the table has been changed or not.
SQL> SELECT * FROM Fruit;
On executing the above query, it will generate the following output as shown below −
+----+-----------+---------+---------+ | ID | NAME | ADDRESS | PRICE | +----+-----------+---------+---------+ | 1 | Apple | Shimla | 2000.00 | | 4 | Banana | AP | 1000.00 | | 5 | JackFruit | Ooty | 1000.00 | +----+-----------+---------+---------+Advertisements