Tutorials

SQL Clause and Operator


SQL NOT NULL


In SQL, NOT NULL is used on column(s) along with WHERE to find records that do not havie null value in specified column(s).

If there is a column where inserting value is not mandatory then it may be ommited while value insertion. In case no value is inserted in the column then it contains null value.

A field is considered to have NULL value if it has been left blank.

Syntax for NULL

SELECT [*|columns]
FROM table_name
WHERE column_name IS NOT NULL;

Example of NULL

We will be using 'tih_Courses' table for demonstration purpose. Suppose we have following data in the table.

tih_Courses
Course_ID Course_Name Professor Mode_of_Training
001 .NET Mukesh Tiwari Online and Offline
002 Java Rajneesh Shukla Online and Offline
003 ANSI SQL Rajneesh Shukla  
004 Basics of Computer Shweta   

We see value is not inserted in mode of training column as during insertion we chose not to insert value into it. So blank columns will have NULL value.

SELECTFROM tih_Courses
WHERE Mode_of_Training IS NOT NULL;

On executing the above query successfully, we will get following result:

tih_Courses
Course_ID Course_Name Professor Mode_of_Training
001 .NET Mukesh Tiwari Online and Offline
002 Java Rajneesh Shukla Online and Offline
 


Please Share this page
Views : 24