三张表的字段格式都一模一样 怎么合并成一张表

a表       b表      c表                 d表
id name   id name  id name      ?=    id,name

解决方案 »

  1.   

    select * from (
    select id,name from a表
    union all
    select id,name from b表
    union all
    select id,name from c表)d
      

  2.   


    select id,name into D from a表
    union 
    select id,name from b表
    union 
    select id,name from c表union和union all的区别是一个过滤重复记录一个不过滤重复记录
      

  3.   

    --查詢3張表的所有記錄,則用
    select * from (
    select id,name from a表
    union all
    select id,name from b表
    union all
    select id,name from c表)d--查詢3張表中沒有重復的記錄,則用
    select * from (
    select id,name from a表
    union 
    select id,name from b表
    union 
    select id,name from c表)d--union all 比 union 的效率高
      

  4.   

    三张表的字段格式都一模一样 怎么合并成一张表

    a表       b表      c表                 d表
    id name   id name  id name      ?=    id,nameselect * into d from
    (
      select * from a
      union all
      select * from b
      union all
      select * from c
    ) t
      

  5.   


    union all 
    union --会合并相同项
      

  6.   

    union all 
    union --会合并相同项
      

  7.   


    union all 
    union --会合并相同项