读书人

union 的有关问题

发布时间: 2012-02-27 10:00:22 作者: rapoo

union 的问题
a 表
cu_id cur_name date
1 abc 2006
2 def 2007
5 efg 2008
b 表
cur_id cur_name date
1 abc 2007
1 abc 2007
3 def 2008

用a union b 时
线保证 b 里边的数据
也就是 b 里边要是有的话
union 后的结果就是 b 的数据
a 表和表合并后为

1 abc 2007
1 abc 2007
3 def 2008
5 efg 2008



[解决办法]
seelct * from b
union all
select * from a
where not exists (
select 1 from b where
cur_name =a.cur_name
)

读书人网 >SQL Server

热点推荐