您现在的位置是:首页 > SQLServer

SQLServer

多表部分对应列联合查询(重要)

2020-11-21 11:29:44 SQLServer admin
create table wggfcusmq_A(ID int, Name varchar(10), Sex varchar(10))insert into wggfcusmq_Aselect 1, ww, 12 union allsele

create table wggfcusmq_A(ID int, Name varchar(10), Sex varchar(10))
insert into wggfcusmq_A
select 1, 'ww', 12 union all
select 2, 'aa', 13


create table wggfcusmq_B(ID int, Name varchar(10), Glass varchar(10))
delete wggfcusmq_B
insert into wggfcusmq_B
select 1, 'ww', 'A' union all
select 3, 'bb', 'B'

==============
select ISNULL(a.id,b.id)as ID,
name=ISNULL(a.name,b.name),
sex=ISNULL(sex,''),
class=ISNULL(Glass,'')from wggfcusmq_A a full join wggfcusmq_B b on a.id=b.id