34,593
社区成员
发帖
与我相关
我的任务
分享
create table tb1(id int identity(1,1),name varchar(10),remark varchar(50) default '');
create table tb2(xid int identity(1,1),name varchar(10));
insert into tb1(name)
select 'a'
union all select 'b'
union all select 'c'
insert into tb2(name) select 'x'
select * from tb1 where id in(select id from tb2)
select * from tb1 where id in(select xid from tb2)
drop table tb1
drop table tb2;
select * from tb1 a where exists (select id from tb2 where a.id = id )
EXISTS
create table tb1(id int identity(1,1),name varchar(10),remark varchar(50) default '');
create table tb2(xid int identity(1,1),name varchar(10));
insert into tb1(name)
select 'a'
union all select 'b'
union all select 'c'
insert into tb2(name) select 'x'
select * from tb1 where exists (select id from tb2)
select * from tb1 where exists (select xid from tb2)
drop table tb1
drop table tb2;
select * from tb1 where exists (select id from tb2 where tb1.id = id )
这个也一样,也是错了!
select * from tb1 where id not in (select id from tb2)
这个本来是,3条记录,可是一条都没有出!