SQL Null

HTML
CSS
C#
SQL

SQL Null

First of all we should know what a null value is. Null values are used to represent missing unknown data. A NULL value is different from a zero value or a field that contains spaces. A field with a NULL value is one that has been left blank during record creation!

There can be two conditions:

  1. Where SQL is NULL
  2. Where SQL is NOT NULL

It is not possible to test for NULL values with comparison operators, such as =, <, or <>.

We will have to use the IS NULL and IS NOT NULL operators instead.

Example:

SHOW ME the names of people in the IT department.

SELECT column_names FROM table_name WHERE column_name IS NOT NULL;

There is an example of student table:

student

Let’s see the query to get all the records where marks is NULL:

SELECT SIR_NAME, NAME, MARKS FROM STUDENTS WHERE MARKS IS NULL ;

It will return the following records:

records

Let’s see the query to get all the records where marks is NOT NULL:

SELECT SIR_NAME, FIRSTNAME, MARKS FROM STUDENTS WHERE MARKS IS NOT NULL;

It will return the following records:

Course Video

1. Write SQL Query to get all the columns from Person.Person table where title is not null.

OUTPUT 

2. Write SQL Query to get BusinessEntityID, TerritoryID, Bonus From Sales_SalesPerson where SalesQuota IS NULL

OUTPUT 

3. Write SQL Query to get BuinessEntityID, PersonType from  Person.Person Where title is Null.

OUTPUT 

4. Write a SQL Query to get all the columns from Person.Person where suffix is Null.

OUTPUT 

5. Write Sql query to get all the columns from Sales.SalesPerson table  where TerritoryId is null.

OUTPUT