作者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