mysql isnull用法讲解 mysql 可以使用 isnull() 函数。不过它的工作方式与微软的 isnull() 函数有点不同。 我们先来看几个is null sql用法: select * from newtable where name is null //取得newtable表中name为null值的所有数据 select * from tbas_table
mysql isnull用法讲解
mysql 可以使用 isnull() 函数。不过它的工作方式与微软的 isnull() 函数有点不同。
我们先来看几个is null sql用法:
select * from newtable where name is null //取得newtable表中name为null值的所有数据
select * from tbas_table where title not is null //取得tbas_table表中title字段不为null的所有数据
再看如下语句:
select `click`,`title`,`created` from dcfsda_table where click is not null
再看如下语句:
select `id`,`title`,`describle` from bnsdh_table where describle is not null
我们可以看到此表有 1025014 数据,其中 describle 列只有一条是 null 值。也就是 describle 列的索引会存储此列的 1025014 条记录的信息,只有一条没有存。在选择怎么的时候, db2 优化器会试着用这样两种方式,第一种是从表中取出每条记录,然后看它的 describle 值是否为空。第二种是,先从索引找到 describle 列所有非空的数据在表中的位置,然后在扫描表时,如碰到这些位置,则不用取出数据判断是否为空,直接跳到下一条记录。
is not null 高效率应用:
有些地方有这样的说法,is not null 不能利用索引,所以要将其改写成其他语句,以便能够利用索引提高效率。下面是测试情况:
sql 语句: select click from bsga_table where click is not null
改写后的sql 语句 : select click from bsga_table where click > 0 and click < 100001
无论是 is null 还是 is not null ,,并不是如网上所说的 is null 或者 is not null 不能利用索引,而是在不同的表数据结构环境下,有可能会利用索引有可能不利用索引,而决定如何执行查询的标准就是性能。
扩展阅读:
is null 是判断值是不是null,用=null则是跟null进行比较运算,而null跟任何值作比较运算结果都是false,也就不会有任何查询纪录。
比如你有条记录值是null,用is null能查出来,用=null就不会返回任何结果。
注:更多精彩文章请关注三联编程教程栏目。
.syntaxhighlighter{padding-top:20px;padding-bottom:20px;}
申明:本教程内容由威凡网编辑整理并提供IT程序员分享学习,如文中有侵权行为,请与站长联系(QQ:254677821)!