what#39;s the difference between is not null and lt;gt;#39; #39;(is not null 和 lt;gt; 有什么区别)
问题描述
看我的例子,两个代码有什么区别?
Look my example, what's the difference between two codes?
Select name from customers where name is not null
Select name from customers where name <> ''
推荐答案
他们做完全不同的事情.
They do completely different things.
Select name from customers where name is not null
此选项选择在名称字段中具有值的任何客户.这些值可以包括"以及诸如山姆"、约翰琼斯"、漂亮的金发女孩"之类的内容.
This one selects any customer who has a value in the name field. Those values can include '' as well as things like 'Sam', 'John Jones', 'pretty blonde girl'.
Select name from customers where name <> ''
这将选择至少在 Sql Server 中不为空或空白的所有名称.其他数据库可能会以不同的方式处理此问题.它还排除 Null 的原因是 Null 不能作为比较的一部分,因为它的定义意味着我们不知道该字段的值是什么.
This will select all names that are not null or blank In Sql Server at least. Other databases may handle this differently. The reason why it also excludes Null is that Null cannot be part of a comparison since it by definition means we don't have a clue what the value of this field is.
如果您想同时返回真实姓名和空值,并且只排除空字符串.在 SQL Server 中,您将执行以下操作:
If you wanted to return both real names and null values and only exclude the empty strings. In SQl Server you would do:
Select name from customers where coalesce(name, 'Unknown') <>''
这篇关于is not null 和 <>' 有什么区别'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:is not null 和 <>' 有什么区别'


- SQL 临时表问题 2022-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01