select A from table1 where 条件1
查询结果为
1
2
3
select B from table2 where 条件2
查询结果为
甲
乙
丙有没有什么办法把两个结果拼接在一起
使得查询结果为
1甲
2乙
3丙
查询结果为
1
2
3
select B from table2 where 条件2
查询结果为
甲
乙
丙有没有什么办法把两个结果拼接在一起
使得查询结果为
1甲
2乙
3丙
from table1 where 条件1select identity(int,1,1) as id,B into #t2
from table2 where 条件2select a.f1,b.f1 from
#t1 a,#t2 b
where a.id=b.id
连接查询...
没法连上阿 回复人:yczealot() ( 四级(中级)) 信誉:98
你的意思是用临时表:)我试试看阿
insert A select 1
insert A select 2
insert A select 3
create table B(col varchar(10))
insert B select '甲'
union all select '乙'
union all select '丙'select ID=identity(int, 1, 1), * into #A from A
select ID=identity(int, 1, 1), * into #B from Bselect A.col, B.col
from #A A
left join #B B on A.ID=B.ID--result
col col
----------- ----------
1 甲
2 乙
3 丙(3 row(s) affected)
甲是第二个查询的第一个对应规律就是第一个对应第一个,第二个对应第二个
-----------------------------------------------------
如果是这样的规律的话,marco08(天道酬勤) ( ) 信誉:100 Blog 的就是正解.但是如果需要严谨一点,那么你所谓的"第一个对应第一个",这里的第一第二是按什么规则来排序的?如果不指明ORDER BY的字段,那么有可能每次查询出来的结果集的顺序不同,就会导致第一第二的不同.
可是我想问入过我第二次执行这个存储过程的时候我应该怎么做阿
直接执行的话会说已经有这个存储过程,把create 改成alter会说第一行(附近有错阿
select ID=identity(int, 1, 1), * into #B from B order by colselect A.col, B.col
from #A A
left join #B B on A.ID=B.ID