The value of the null column does not participate in the comparison

If the database has table emp:

empno name   age

001      lucy      22

002      lily        null

003      lilei       null

004      lucy      null

005      pear      null

006      pear      null

 

When executing sql:

SELECT empno FROM `emp` where age != 22;

There is not a single one returned;

 

Conclusion: The null value is not involved in the comparison , age != 22 , all those columns with null are filtered out.

Pay attention to this feature at the critical moment. 

 =====================

In SQL, a comparison of a NULL value with any other value (even NULL) is never "true". Expressions containing NULL always result in a NULL value

 http://doc.mysql.cn/mysql5/refman-5.1-zh.html-chapter/problems.html#problems-with-null

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326565455&siteId=291194637