NULL Values :
A value of NULL indicates that the value is unknown. A value of NULL is different
from an empty or zero value. No two null values are equal.
Comparisons between two null values, or between a NULL and any other value,
return unknown because the value of each NULL is unknown.
Inserting Null Values In MySQL:
Consider the below table :
Order_id | Name | Amount |
---|---|---|
O001 | chandan | 2500 |
O002 | Adhiraj | 3500 |
Now if you want to insert the null values then your query will be :
QUERY :
INSERT INTO Order(order_id)
values("O003")
Result :
Order_id | Name | Amount |
---|---|---|
O001 | chandan | 2500 |
O002 | Adhiraj | 3500 |
O003 | NULL | NULL |
Note : if you want to insert the blank space instead of Null values then your query will be :
Query :
INSERT INTO Order(order_id, Name)
values("O004", "" )
Result :
Order_id | Name | Amount |
---|---|---|
O001 | chandan | 2500 |
O002 | Adhiraj | 3500 |
O003 | NULL | NULL |
O004 | 0 |
Insert Null value in SQL
Consider the below table :Order_id | Name | Amount |
---|---|---|
O001 | chandan | 2500 |
O002 | Adhiraj | 3500 |
Note : Table column property should not set to NOT NULL.
Now if you want to insert the null values then your query will be :
QUERY :
Insert Into Order(order_id, name, Amount)
Values (null, null, null)
Result :
Order_id | Name | Amount |
---|---|---|
O001 | chandan | 2500 |
O002 | Adhiraj | 3500 |
null | null | null |
Order_id | Name | Amount |
---|---|---|
O001 | chandan | 2500 |
O002 | Adhiraj | 3500 |
O003 | ||
O004 | ||
O005 | NULL | NULL |
Query to fetch blank rows in MySql
Select *from order
Where Name = ""
Result :
Order_id | Name | Amount |
---|---|---|
O003 | ||
O004 |
Query to fetch NULL rows in MySql
Select *from order
Where Name IS NULL
Result :
Order_id | Name | Amount |
---|---|---|
O005 | NULL | NULL |
Query to fetch NOT NULL rows in MySql
Select *from order
Where Name IS NOT NULL
Result :
Order_id | Name | Amount |
---|---|---|
O001 | chandan | 2500 |
O002 | Adhiraj | 3500 |
O003 | ||
O004 |
Order_id | Name | Amount |
---|---|---|
O001 | chandan | 2500 |
O002 | Adhiraj | 3500 |
O003 | ||
O004 | ||
O005 | NULL | NULL |
Query to fetch blank rows in Sql
Select *from order
Where Name = ""
Result :
Order_id | Name | Amount |
---|---|---|
O003 | ||
O004 |
Query to fetch NULL rows in Sql
Select *from order
Where Name IS NULL
Result :
Order_id | Name | Amount |
---|---|---|
O005 | NULL | NULL |
Query to fetch NOT NULL rows in Sql
Select *from order
Where Name IS NOT NULL
Result :
Order_id | Name | Amount |
---|---|---|
O001 | chandan | 2500 |
O002 | Adhiraj | 3500 |
O003 | ||
O004 |
No comments:
Post a Comment