mysql中is null 與 = null

來源:互聯網
上載者:User

標籤:class   情境   tab   mic   symbol   size   space   code   不為   

==null與is null老是弄錯,現在總結一下工作中遇到過的錯誤。

1、在查詢的時候

select * from user where name is null;

select * from user where name is not null;

2、在更新的時候

update user set name = null where id = 1;

3、count(1)與limit無法同時使用

select count(1) from user where name is not null limit 1;

返回的是姓名不能於空的使用者數量,與limit無關。

4、情境:每個使用者有一個備忘屬性,現尋找出備忘不為“加一份飯”的使用者(包括沒有填寫備忘的),此備忘預設為空白,有以下幾個選項:“加一份飯”,“要加辣”,“少放油”

select * from user where ifnull(remark, ‘‘ ") != "加一份飯 "

注意:如果這樣寫:select * from user where remark != "加一份飯 ";

那麼只會查詢出“要加辣”、“少放油” 這兩項的記錄。

 

mysql中is null 與 = null

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.