建立一个临时表,将以上两张表的数据插入,然后select出来,方法比较笨.不过实用.看哪位有什么好点的办法.

解决方案 »

  1.   

    select id, field1 from a
    union
    select id, field from border by id
      

  2.   

    select  id,  field1  from  a  
    union  all
    select  id,  field  from  b  
    where not exists(select 1 from a where a.id=b.id);
      

  3.   

    这样最好.
    select id from aa
    union
    select id from bb
      

  4.   

    又来晚了,union比union all速度慢
      

  5.   

    select  id,  field1  from  a  
    union  all
    select  id,  field  from  b  
    where not exists(select 1 from a where a.id=b.id);效率高.
      

  6.   

    select  id,  field1  from  a  
    union  all
    select  id,  field  from  b  
    where not exists(select id from a where a.id=b.id);
    是正确的