有id且连续 select * into 表 from ( select y c from from 表1 where id between 25 and 28 union all select y c from from 表2 where id between 25 and 28 ) A 没有(就用主键)或id不连续的话 select top 4 y c from 表1 where id not in(select top 28 y c from 表1) union all select top 4 y c from 表1 where id not in(select top 28 y c from 表2)
select * from 表1 union all select * from 表2
select * from (select y c from from 表1 where id between 25 and 28) a, (select y c from from 表2 where id between 25 and 28) b
select identity(int,1,1) id ,yc into #tmp1 from a where .... select identity(int,1,1) id ,yc into #tmp2 from a where ....select a.yc,b.yc from #tmp1 a,#tmp2 b where a.id=b.id
select * into 表 from (
select y c from from 表1 where id between 25 and 28
union all
select y c from from 表2 where id between 25 and 28
) A
没有(就用主键)或id不连续的话
select top 4 y c from 表1 where id not in(select top 28 y c from 表1)
union all
select top 4 y c from 表1 where id not in(select top 28 y c from 表2)
union all
select * from 表2
(select y c from from 表1 where id between 25 and 28) a,
(select y c from from 表2 where id between 25 and 28) b
select identity(int,1,1) id ,yc into #tmp2 from a where ....select a.yc,b.yc from #tmp1 a,#tmp2 b where a.id=b.id