一道面试题,求解
表a
Id fname lname
1 zhu liu
2 ma ling
3 wang hua
表b
Id age tele
1 20 32425215
3 23 543242
5 21 543543543
求 id fname lname age tele
1 zhu liu 20 32425215
2 ma ling
3 wang hua 23 543242
5 21 543543543
------解决方案--------------------用full join 就可以了
------解决方案--------------------select ID ,isnull(fname, ' ') fname
,isnull(lname, ' ') lname
,isnull(age,0) age
,isnull(tele, ' ')tele
from a
full outer join b on a.id =b.id
------解决方案--------------------declare @a table(Id int,fname varchar(8),lname varchar(8))
insert into @a
select 1, 'zhu ', 'liu '
union select 2, 'ma ', 'ling '
union select 3, 'wang ', 'hua '
declare @b table(Id int,age int,tele int)
insert into @b
select 1,20,32425215
union select 3,23,543242
union select 5,21,543543543
select * from @a;
select * from @b;
select a.id,fname,lname,age,tele from @a a inner join @b b on a.id=b.id
union select a.id,fname,lname,age,tele from @a a left join @b b on a.id=b.id
union select b.id,fname,lname,age,tele from @a a right join @b b on a.id=b.id
------解决方案--------------------select * from (
select id,fname from 表a inner join 表b on 表a.ID!=表b.ID
union all
select id,o.fname+p.fname from 表a o inner join 表b p on o.ID=p.ID
) as a
------解决方案--------------------full join 足够了
------解决方案--------------------select * from
表A a
full join
表B b
on a.id=b.id
------解决方案--------------------[SQL SERVER 2000 全连接 FULL OUTER JOIN | FULL JOIN]
SELECT * FROM a FULL JOIN b ON a.id = b.id
------解决方案--------------------select isnull(表a.id,表b.id) as id,表a.fname,表a.lname,表b.age,表b.tele
from 表a full join 表b
on 表a.id=表b.id
------解决方案--------------------select a.fname,a.lname,b.age ,b.tele from
( a join b on a.ID= b.ID)
这样解决不就可以了吗~!