SQL Null operator
Description
SQL Null check is performed using either IS NULL or IS NOT NULL to check whether a value in a field is NULL or not.
When a field value is NULL it means that the database assigned nothing in that field for that row. The NULL is not zero or blank. It represents an unknown or inapplicable value. It can’t be compared using AND / OR logical operators. The special operator ‘IS’ is used with the keyword ‘NULL’ to locate ‘NULL’ values. NULL can be assigned in both type of fields i.e. numeric or character type of field.
Syntax:
SELECT [column_name1,column_name2 ] FROM [table_name] WHERE [column_name] IS [NOT] NULL;
Parameters:
Name | Description |
---|---|
column_name,column_name1.. | Name of the column of the table. |
table_name | Name of the table. |
Example:
Sample table: listofitem+----------+---------------------------+-------------------------------------+-------------------------------------+ | ITEMCODE | ITEMNAME | BATCHCODE | CONAME | +----------+---------------------------+-------------------------------------+-------------------------------------+ | I001 | CHOCOLATE | DM/2007-08/WBM%1 | | | I003 | HOT DOG | DM/2007-08/WB1 | ABJ ENTERPRISE | | I002 | CONDENSED MILK | DM/2007-08/WBM%2 | ABJ CONCERN | +----------+---------------------------+-------------------------------------+-------------------------------------+
To get data of all columns from the 'listofitem' table with following condition -
1. coname column contain NULL value,
the following sql statement can be used :
SQL Code:
SELECT *
FROM listofitem
WHERE coname IS NULL;
Output:
Sql Not null operator
Sample table: listofitem+----------+---------------------------+-------------------------------------+-------------------------------------+ | ITEMCODE | ITEMNAME | BATCHCODE | CONAME | +----------+---------------------------+-------------------------------------+-------------------------------------+ | I001 | CHOCOLATE | DM/2007-08/WBM%1 | | | I003 | HOT DOG | DM/2007-08/WB1 | ABJ ENTERPRISE | | I002 | CONDENSED MILK | DM/2007-08/WBM%2 | ABJ CONCERN | +----------+---------------------------+-------------------------------------+-------------------------------------+
To get data of all columns from the 'listofitem' table with the following condition -
1. 'coname' column must have a value,
the following sql statement can be used:
SQL Code:
SELECT *
FROM listofitem
WHERE coname IS NOT NULL;
Output:
Outputs of the said SQL statement shown here is taken by using Oracle Database 10g Express Edition.
Check out our 1000+ SQL Exercises with solution and explanation to improve your skills.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/sql/null-operator/null-operator.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics