码迷,mamicode.com
首页 > 数据库 > 详细

mysql中is null 与 = null

时间:2016-12-30 18:31:39      阅读:243      评论:0      收藏:0      [点我收藏+]

标签: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

标签:class   场景   tab   mic   symbol   size   space   code   不为   

原文地址:http://www.cnblogs.com/mucheng/p/6114885.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!