日期:2014-05-17  浏览次数:20343 次

mysql 的sql语句
表A 
id name
1 A
2 B
3 C
表B
id test
2 A
4 B
我想要的结果是
id name test
1 A NULL
2 B A
3 C NULL
4 NULL B
该怎么写sql语句

------解决方案--------------------
SQL code
if object_id('[TBA]') is not null drop table [TBA]
go
create table [TBA] (id int,name nvarchar(2))
insert into [TBA]
select 1,'A' union all
select 2,'B' union all
select 3,'C'

if object_id('[TBB]') is not null drop table [TBB]
go
create table [TBB] (id int,test nvarchar(2))
insert into [TBB]
select 2,'A' union all
select 4,'B'

select * from [TBA]
select * from [TBB]


SELECT ISNULL(TBA.id,TBB.id) AS  id,NAME,test
FROM dbo.TBA
FULL JOIN TBB ON TBA.id = TBB.id

/*
id    NAME    test
1    A    NULL
2    B    A
3    C    NULL
4    NULL    B*/