카테고리 없음

SQL NULL Values

AKA.DM 2022. 4. 21. 13:18
반응형

a field with a NULL value is a field with no value.

 

If a field in a table is optional, it is possible to insert a new record or update a record without adding a value to this field. then, the field will be saved with a NULL value.

 

How to test for NULL values?

it is not possible to test for NULL values with comparison operator, such as = < or <>

We will have t o use the IS NULL and IS NOT NULL operator instead.

 

IN NULL syntax

 

SELECT column_names

FROM table_name

WHERE column_name IS NULL ;

 

IS NOT NULL syntax

 

SELECT colomn_names

FROM table_name

WHERE column_name IS NOT NULL ;

 

The demo database goes like below 

 

IF i want to find the NULL Values from City 

 

SELECT City

FROM Customers
WHERE City IS NULL ; 

 

The result like that.

viceversa, IN NOT NULL with same condition

 

SELECT City
FROM Customers
WHERE City IS NOT NULL ; 

SELECT CustomerName, address, Country

FROM Customers

WHERE Country IS NOT NULL ; 

반응형