select A from table1 where 条件1
查询结果为
1
2
3
select B from table2 where 条件2
查询结果为


丙有没有什么办法把两个结果拼接在一起
使得查询结果为
1甲
2乙
3丙

解决方案 »

  1.   

    select identity(int,1,1) as id,A into #t1 
    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
      

  2.   

    2个table必须要有主外键关系...
    连接查询...
      

  3.   

    回复人:iColor(iColor) ( 一级(初级)) 信誉:100
    没法连上阿 回复人:yczealot() ( 四级(中级)) 信誉:98
    你的意思是用临时表:)我试试看阿
      

  4.   

    create table A(col int)
    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)
      

  5.   

    1是第一个查询的第一个,
    甲是第二个查询的第一个对应规律就是第一个对应第一个,第二个对应第二个
    -----------------------------------------------------
    如果是这样的规律的话,marco08(天道酬勤) ( ) 信誉:100    Blog 的就是正解.但是如果需要严谨一点,那么你所谓的"第一个对应第一个",这里的第一第二是按什么规则来排序的?如果不指明ORDER BY的字段,那么有可能每次查询出来的结果集的顺序不同,就会导致第一第二的不同.
      

  6.   

    marco08(天道酬勤) 兄,你给的最接近我要的东西啊
    可是我想问入过我第二次执行这个存储过程的时候我应该怎么做阿
    直接执行的话会说已经有这个存储过程,把create 改成alter会说第一行(附近有错阿
      

  7.   

    臭虫兄说的有道理啊,我要写得程序里有order by 语句的,求助时忘记写了
      

  8.   

    select ID=identity(int, 1, 1), * into #A from A order by col
    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
      

  9.   

    如果是SQL2005可以不用,2000或以下版本需要生成递增列