sql - union all

我的 表1中有字段([c],[num]),
记录诸如:
[c] [num]
0   188
1   167
2   373
3   378
4   377
表二也有同样的字段,记录有的id不同,
请问我该怎么合并他们呢?根据id.

ref: http://bbs.csdn.net/topics/390952297

代码为:

SELECT 	a.[c], 

		a.[num]

FROM [test].[dbo].[b] a

left join [test].[dbo].[a] b on a.[c]=b.[c]

union  all

select 

		b.[c], 

		b.[num] from [test].[dbo].[b] a

right join [test].[dbo].[a] b on a.[c]=b.[c]

where a.id is null

 

你可能感兴趣的:(UNION ALL)