34,593
社区成员
发帖
与我相关
我的任务
分享
select *
from B t
where not exists(select 1 from A where u_name = t.u_name and u_pcode = t.u_pcode)
create table a (u_name varchar(10) , u_pcode varchar(18))
create table b (u_name varchar(10) , u_pcode varchar(18))
insert into a values('张三', '430626198306130008')
insert into a values('李四', '511025198103152192')
insert into a values('王五', '61050219800920721X')
insert into a values('赵六', '430381198209243670')
insert into b values('张三', '430626198306130009')
insert into b values('李四', '511025198103152192')
insert into b values('王五', '61050219800920721X')
insert into b values('霍七', '632126198505152718')
go
--a表有,b表没有
select a.* from a where not exists(select 1 from b where u_name = a.u_name and u_pcode = a.u_pcode)
/*
u_name u_pcode
---------- ------------------
张三 430626198306130008
赵六 430381198209243670
(所影响的行数为 2 行)
*/
--b表有,a表没有
select B.* from b where not exists(select 1 from a where u_name = B.u_name and u_pcode = B.u_pcode)
/*
u_name u_pcode
---------- ------------------
张三 430626198306130009
霍七 632126198505152718
(所影响的行数为 2 行)
*/
drop table a , b
--a表有,b表没有
select a.* from a where not exists(select 1 from b where u_name = a.u_name and u_pcode = a.u_pcode)
--b表有,a表没有
select B.* from b where not exists(select 1 from a where u_name = B.u_name and u_pcode = B.u_pcode)