zoukankan      html  css  js  c++  java
  • mysql : 使用不等于过滤null的问题

    table A 有字段name,age。

     

    id name     age

    1   null       11

    2   jack       12

    3   tony      13

     

    select * from table A where name != 'tony'

    查询结果只有id = 2 的记录;

    分析原因:因为 NULL 不是一个「值」,而是「没有值」。「没有值」不满足「值不等于1」这个条件。所以 mysql 尽量不要默认值是 NULL。

    要查询出来id = 1的记录有两种方案:

    方案一:

              select * from table A where name != 'tony'  or name is null;

    方案二:

            select * from table A where IFNULL(name,'')  !=  'tony'

  • 相关阅读:
    #4702. gcd
    独特的树叶

    搞笑的代码 ( funny )
    越野赛车问题
    删边(cip)
    最长公共子序列
    美食节
    线段树
    新年快乐
  • 原文地址:https://www.cnblogs.com/enchaolee/p/13673171.html
Copyright © 2011-2022 走看看