The unique key can contain null values, and each null value is unique (that is, the null! =null) "Understand

Source: Internet
Author: User

Since I recently wrote a paper on string fuzzy retrieval, we began to study the index problem in a more detailed database (MySQL), and changed to the library to borrow the effective MySQL SQL statement optimization (Ronald Bradford, Lishee). I saw it in there today. The unique key can contain null values, and each null value is unique (that is, the null! =null) ". The first reaction is: I go, what ghost? It's not a man's thing!! In fact, the computer industry a lot of such words, think and then went online to find write information!

Use the SQL SELECT command of the WHERE clause to get the data from the MySQL table. However, when we try to give a condition to compare the value of a field or column to NULL, it does not work correctly.

To handle this situation, MySQL provides three large operators

  1. Is null: This operator returns True when the value of the column is null.
  2. is not NULL: the operator returns True when the value of the column is not NULL.
  3. The <=> operator comparison value (unlike the = operator) is ture, even if two null values

The null condition involved is special. You cannot use =null or!=null to find a column with a NULL value. This comparison always tells them whether it is a real failure, because it is impossible. Even the null=null failed.

If you are looking for columns that are or are not NULL, use is NULL or is not NULL.

Reference documents:

1. Detailed explanation of null values in MySQL

2. are not null and!=null and NULL in MySQL

The unique key can contain null values, and each null value is unique (that is, the null! =null) "Understand

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.