条件里面IS NULL和IS NOT NULL是什么意思
请问条件里面IS NULL和IS NOT NULL是什么意思。下面两句返回结果一样。我有点模糊了。
SQL code?SELECT A.* FROM tw_tb AS A LEFT JOIN tw_tb2 AS B ON A.name=B.nameWHERE B.name IS NULL SELECT * FROM tw_tb WHERE NOT EXISTS (SELECT * FROM tw_tb2 WHERE tw_tb.name=tw_tb2.name)
两句的逻辑都是: 查询tw_tb里有,但tw_tb2里没有的数据.
因为你A表left join B 表,显示的A表全部内容,就有a表中的name在B表中找不到,找不到的就是b表
中的name有null值
--举个例子,自己看看结果
if object_id('a') is not null
drop table a
create table a
(
id int primary key identity(1,1),
name nvarchar(20)
)
go
insert into a
select '张三' union all
select '李四' union all
select '王五' union all
select '赵六' union all
select '' union all
select null union all
select '孙七'
go
select * from a
select * from a where name is not null
select * from a where name is null
select * from a where name = ''