Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

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


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 Null operator

Sql Not null operator

Sample table: listofitem


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:

Sql Null operator

Outputs of the said SQL statement shown here is taken by using Oracle Database 10g Express Edition.

See our Model Database.

Practice SQL Exercises

Want to improve the above article? Contribute your Notes/Comments/Examples through Disqus.



SQL: Tips of the Day

SQL Server SELECT into existing table.

INSERT INTO dbo.TABLETWO
SELECT col1, col2
  FROM dbo.TABLEONE
 WHERE col3 LIKE @search_key

This assumes there's only two columns in dbo.TABLETWO - you need to specify the columns otherwise:

INSERT INTO dbo.TABLETWO
  (col1, col2)
SELECT col1, col2
  FROM dbo.TABLEONE
 WHERE col3 LIKE @search_key

Database: SQL Server

Ref: https://bit.ly/3y6tpA3