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 和 <>' 有什么区别'
基础教程推荐
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 在多列上分布任意行 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
