有以下数据
table1
字段:A,   B,   C,  D
    001,  1,   1,  
    002,  1,   1,  A
table2
字段:A,   B,   C,  D
    001,  1,   1,  D
结果要显示为:
字段:A,   B,   C,  D
    001,  1,   1,  
    002,  1,   1,  A
    001,  1,   1,  D
 我的sql是
  select a,b,c,d
from (select table1.a a, table1.b b, table1.c c, table1.d d
from table1
union
select table2.a a,table2.b b, table2.c c, table2.d d
from table2
)
order by d,a

解决方案 »

  1.   

    select *
    from table1
    union
    select *
    from table2
    order by d,a
      

  2.   

    你这样的数据,好象
    select   table1.a   a,   table1.b   b,   table1.c   c,   table1.d   d 
    from   table1 
    union 
    select   table2.a   a,table2.b   b,   table2.c   c,   table2.d   d 
    from   table2 不需要order by也是这结果,你的顺序根本就没变
      

  3.   

    楼主,你写的SQL没问题啊,不过3楼的要更简单一些。