Two issues you need to pay attention to when using MySQL to process null values

Source: Internet
Author: User

Trap 1: NULL values are not necessarily empty

In MySQL databases, null represents a special meaning for some special types of columns, not just a null value. For these special types of columns, you must remember two types. One is what I mentioned above.Times ***** p Data classType. If a null value is inserted into this data type column, it indicates the current time of the system.. The other is a column with the auto_increment attribute.. If a null value is inserted into this attribute column, a positive integer sequence is inserted. If NULL data is inserted in columns of other data types, such as values, a null value is inserted.

Trap 2: NULL values are not necessarily equal to null characters

The first is the keyword is null and is not null. If you want to determine whether a field contains NULL data, you need to use special keywords. The former indicates that this field is empty, and the latter indicates that this field is not empty. These two keywords are very useful in the query condition of the SELECT statement. To query all users whose phone numbers are empty (they need to add their phone number information), you can add the "is not null" keyword to the query conditions.

Second, statistical functions such as Count also have special applications on null values. If you want to count the number of users with phone numbers in the user information table, you can use the count function and use the phone number as a parameter. This function automatically ignores NULL data during the statistical process. At this time, the statistics show the user information with phone numbers. If null characters are used, this function counts them. As shown in, when calculating the two records just created, the system's statistical result is 1 rather than 2. The system automatically ignores 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.