简体   繁体   English

mysql 查询中的“column is not null”和“column?=''”和'column<>'''有什么区别?

[英]What is the difference between “column is not null” and “column !=''” and 'column<> ''' in mysql query ?

If "emp" is one of the column of the table in MySQL Database, please let me know, the difference between below queries:如果“emp”是 MySQL 数据库中表的列之一,请告诉我,以下查询之间的区别:

emp <> '' and emp not null emp <> ''emp not null

I'm confused, please help me.我很困惑,请帮助我。

The comparison with '' checks if the string is equal to the empty string, and can always be performed.''的比较检查字符串是否等于空字符串,并且始终可以执行。

The IS NOT NULL test is only meaningful if the database column is nullable.仅当数据库列可以为空时, IS NOT NULL测试才有意义。 You would make it nullable on purpose, specifically to be able to tell the difference between "I know this value, and it happens to be a blank" and "this value is not applicable here, or I do not know it".你会故意让它为空,特别是能够区分“我知道这个值,它恰好是一个空白”和“这个值在这里不适用,或者我不知道”。

You might also want to check out what the MySql docs say regarding NULL values .您可能还想查看 MySql 文档关于NULL的说法。

emp <> '' won't match a column that is null. emp <> ''不会匹配 null 的列。 For null tests, you have to use emp is not null , because null doesn't match anything.对于 null 测试,您必须使用emp is not null ,因为 null 不匹配任何内容。

emp <> '' tests if the value is different of the empty string whereas emp is not null tests is your value is different of null. emp <> ''测试值是否与空字符串不同,而emp is not null测试您的值是否与 null 不同。 When comparing with null, you should always use is null or is not null与 null 比较时,应始终使用is nullis not null

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM