当前位置: 代码迷 >> Sql Server >> mysql 的sql话语
  详细解决方案

mysql 的sql话语

热度:60   发布时间:2016-04-25 01:18:42.0
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]gocreate table [TBA] (id int,name nvarchar(2))insert into [TBA]select 1,'A' union allselect 2,'B' union allselect 3,'C'if object_id('[TBB]') is not null drop table [TBB]gocreate table [TBB] (id int,test nvarchar(2))insert into [TBB]select 2,'A' union allselect 4,'B'select * from [TBA]select * from [TBB]SELECT ISNULL(TBA.id,TBB.id) AS  id,NAME,testFROM dbo.TBAFULL JOIN TBB ON TBA.id = TBB.id/*id    NAME    test1    A    NULL2    B    A3    C    NULL4    NULL    B*/
  相关解决方案