[英]Difference between (NULL) and empty in mysql column values
I am working in a company where we use Spring -Hibernate and mysql database at backend.我在一家公司工作,我们在后端使用 Spring -Hibernate 和 mysql 数据库。
There is a table tc_wallet有一个表tc_wallet
In this table i have an column tips_type which has values在这个表中,我有一列tips_type ,它有值
''
(empty) ''
(空)NULL
--> No value has been initialized NULL
--> 没有值被初始化Now when i fire a query:现在,当我发起查询时:
SELECT *
FROM `tc_wallet`
WHERE
login_id = 'gaurav.wakharkar'
AND `delete_flag` = 'F'
AND `tips_type` != 'Collection'
I get results which has column value as '' (empty).我得到的结果列值为 '' (空)。
Login_id tips_type
gaurav.wakharkar
gaurav.wakharkar
gaurav.wakharkar
But even (NULL) is != 'Collection' should satisfy the above condition.但即使 (NULL) is != 'Collection' 也应该满足上述条件。
So according to me the result should have been .所以在我看来,结果应该是 .
Login_id tips_type
gaurav.wakharkar
gaurav.wakharkar
gaurav.wakharkar
gaurav.wakharkar (NULL)
gaurav.wakharkar (NULL)
Is there some issue while checking/comparing values with (NULL) ?检查/比较值与 (NULL) 时是否存在一些问题?
Does it behave differently ?它的行为是否不同?
To check for nullness, you want to use IS NULL
.要检查空性,您需要使用
IS NULL
。 Comparing NULL
to something else with the equality operator (or the inequality operator) is always false.使用相等运算符(或不等运算符)将
NULL
与其他内容进行比较总是错误的。
Consider:考虑:
SELECT *
FROM `tc_wallet`
WHERE
login_id = 'gaurav.wakharkar'
AND `delete_flag` = 'F'
AND (`tips_type` IS NULL OR `tips_type` != 'Collection')
change your query to将您的查询更改为
SELECT
*
FROM
`tc_wallet`
WHERE login_id = 'gaurav.wakharkar'
AND `delete_flag` = 'F'
AND (`tips_type` != 'Collection' or `tips_type` is null)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.