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'

  • 相关阅读:
    POST
    界面,数据下载
    异步下载
    Cell
    循环&信息添加&颜色修改
    通讯录
    图片循环
    多删搜索
    图片滚动
    TableView
  • 原文地址:https://www.cnblogs.com/enchaolee/p/13673171.html
Copyright © 2011-2022 走看看