返回NULL值的记录

stgsr 2007-06-12 11:57:40
表p

id 字段1 字段2
1 a ……
2 b ……
3 c ……
4 null ……

select * from a where 字段1<>'c'

结果只返回第1、2条记录,如何让第4条null值的记录也返回。

要求不要改数据。
...全文
305 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
stgsr 2007-07-20
  • 打赏
  • 举报
回复
受教了,谢谢各位。

我本来也是和zjcxc(邹建)一样写,只是到后来判断太多,只是希望看能不能写成一条。

看来是没办法,只能写长一点了。
iseelxj 2007-07-05
  • 打赏
  • 举报
回复
是不是说null,是不和其他值作比较的啊
比如
select * from a where 字段1 <>''
这样的话 字段1为null 的也不会被取出来啊?
Yang_ 2007-06-12
  • 打赏
  • 举报
回复
select * from a where isnull(字段1,'a')<>'c'
显得简洁点,不过效率不好
肥胖的柠檬 2007-06-12
  • 打赏
  • 举报
回复
select * from a where isnull(字段1,'a')<>'c'
Yang_ 2007-06-12
  • 打赏
  • 举报
回复
select * from a where 字段1<>'c'
union all
select * from a where 字段1 is null

DST_good 2007-06-12
  • 打赏
  • 举报
回复
select * from a where 字段1<>'c' or 字段1 is null
zjcxc 元老 2007-06-12
  • 打赏
  • 举报
回复
select * from a where 字段1<>'c' or 字段1 is null
stgsr 2007-06-12
  • 打赏
  • 举报
回复
表名是a,打错了。
fwacky 2007-06-12
  • 打赏
  • 举报
回复
select * from a where 字段1 <>'c' or 字段1 is null
y_dong119 2007-06-12
  • 打赏
  • 举报
回复
哦。就是,还是喜欢钻石的哈
yown 2007-06-12
  • 打赏
  • 举报
回复
都可以,但邹老大的性能要好些!
itzrx 2007-06-12
  • 打赏
  • 举报
回复
select * from a where isnull(字段1,' ')<>'c'
hui_hui_2007 2007-06-12
  • 打赏
  • 举报
回复
这样不是更好吗:
select * from a where isnull(字段1,'')<>'c'
就是将null全部转化为空串比较

34,588

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧