select a,b from t1
union all
select a,b from t2

解决方案 »

  1.   

    老大的正确,我给你测试一下:
    create table t1(a int,b int)
    create table t2(a int,b int)
    insert into t1 select 1,2
    insert into t2 select 3,4
    select * from t1
    union all
    select * from t2
    drop table t1
    drop table t2
    ---------测试结果----------
    1 2
    3 4
      

  2.   

    union all:纵向增加表的长度!,如果想消除重复用union
      

  3.   

    不好意思,还有问题:
    有t1,t2表,
    t1:
    A   B
    1   2
    3   4
    5   0
    t2:
    A   C
    1   10
    3   20
    我想得到:
    A   B  合计
    1   2  10
    3   4  20
    5   0  0 如何做????
    即统计t2表中的数据,为空则为0
      

  4.   

    select a.a,a.b,合计=sum(b.c)
    from t1 a left t2 b on a.a=b.a
      

  5.   

    create table t1(a int,b int)
    create table t2(a int,c int)
    insert into t1 select 1,2
    insert into t1 select 3,4
    insert into t1 select 5,0
    insert into t2 select 1,10
    insert into t2 select 3,20
    select t1.*,isnull(t2.c,0)as 总计 from t1 left join t2 on t1.a=t2.a
    drop table t1
    drop table t2
    --------------测试结果-------------------
    A   B  合计
    1   2  10
    3   4  20
    5   0  0
      

  6.   

    --少写了一点东西
    select a.a,a.b,合计=sum(b.c)
    from t1 a left t2 b on a.a=b.a
    group by a.a,a.b