作者otyootyo (小躌)
看板Database
标题[SQL ] Select where 遇到 null 时会被自动去掉
时间Thu Feb 23 19:13:41 2012
只有一台电脑有遇到这问题
我是用 Mysql
假如
select * from A where B != 0;
时发现连 B = null 的资料都被筛选掉
请问是 mysql 设定被改到或是 bug ?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.120.0.127
1F:→ chunhsiang:select * from A where B is null 02/23 21:59
2F:→ chunhsiang:是将null的资料找出来 02/23 22:00
3F:→ chunhsiang:null在资料库系统中是一个很特别的值 02/23 22:00
4F:→ chunhsiang:select * from A where B is null and B != 0; 02/23 22:11
5F:→ chunhsiang:这应该才是你本文想下的SQL 02/23 22:12
6F:→ chunhsiang:In SQL, the NULL value is never true in comparison 02/23 22:16
7F:→ chunhsiang: to any other value, even NULL. 02/23 22:16
8F:→ chunhsiang:这是官方文件上的定义(在理论上也都是如此) 02/23 22:17
9F:→ chunhsiang:至於为什麽就自己看理论的书就会更了解 还有实作部分 02/23 22:18
10F:推 olycats:真的耶 每次遇到null都很头大 02/23 23:20
11F:推 TeemingVoid:推c大的精采解说 ^^ 02/24 00:05
12F:推 khaos:应该是 B is null or B != 0 02/25 23:55