现在我有两张表ypdebt和spdebt字段如下
表1.A字段 表2.A字段
     101      101    
     102      105
     104      106
我现在要得到一个新表
  新表.A字段
    101
    102
    104
    105
    106
就是要两个表的A字段相加然后取唯一,请问SQL语句怎么写?请各位大侠指教啊?

解决方案 »

  1.   

    select a from table1
    union 
    select a from table2
      

  2.   

    select a from 表1
    union 
    select a from 表2
      

  3.   

    select A from tb1
    union
    select A from tb2
      

  4.   

    select a from A
    union 
    select a from B where exists not (select*from B where A.a=B.a)
      

  5.   

    select 字段 from 表1
    union 
    select 字段 from 表2
      

  6.   


    select A from ypdebt 
    union 
    select a from spdebt
      

  7.   


    select A from ypdebt 
    union 
    select a from spdebt
      

  8.   

    insert into 表1 select * from 表2 where id not exists 表1
      

  9.   

    方法1:
    select a字段 from 表1
    union 
    select a字段  from 表2方法2:
    inset into 表1  select * from 表2 not exists(select * from 表1 where 表1.a字段=表2.a字段)
    select * from 表1你也可以用临时表或变量表抢个沙发先