Special handling of MySQL null value

Source: Internet
Author: User

Instance

Try the following examples:

[Email protected]# mysql-u root-p password;EnterPassword:*******Mysql> UseRunoob;DatabaseChangedmysql>CREATE TABLE Tcount_tbl- ( -Runoob_author varchar(40)Not NULL, -Runoob_count INT- );QueryOk, 0Rows affected(0.05Sec)Mysql>INSERT into Tcount_tbl- (Runoob_author,Runoob_count)Values(' Mahran ', 20);Mysql>INSERT into Tcount_tbl- (Runoob_author,Runoob_count)Values(' Mahnaz ',Null);Mysql>INSERT into Tcount_tbl- (Runoob_author,Runoob_count)Values(' Jen ',Null);Mysql>INSERT into Tcount_tbl- (Runoob_author,Runoob_count)Values(' Gill ', 20);Mysql>SELECT* FromTcount_tbl;+-----------------+----------------+|Runoob_author|Runoob_count|+-----------------+----------------+|Mahran| 20 ||Mahnaz| NULL | |  jen || |  gill |20 |+-----------------+----------------+4in set  ( 0.00 Sec) mysql>   

You can see in the following instance that the = and! = operators are not working:

Mysql> SELECT * from tcount_tbl WHERE runoob_count = NULL;  Empty Set (0.00 sec)mysql> SELECT * from tcount_tbl WHERE runoob_count = NULL;  Empty Set (0.01 sec)          
Instance

If the Runoob_count column in the lookup data table is NULL, you must use is null and is not NULL, as in the following example:

Mysql>SELECT*From Tcount_tbl-WHERE Runoob_count is NULL;+-----------------+----------------+|Runoob_author|Runoob_count|+-----------------+----------------+|Mahnaz|Null|| Jen |Null|+-----------------+----------------+2RowsInch Set (0.00Sec)Mysql>SELECT* FromTcount_tbl-WHERE Runoob_count is not NULL;+-----------------+----------------+|Runoob_author|Runoob_count| +-----------------+----------------+| Mahran |20 ||  gill |20 |+-----------------+----------------+2in set  ( 0.00 Sec)          

Special handling of MySQL null values

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.