如何查5张表内的相同字段5张表内都有 id idcard phone 三个相同的字段,但是每张表的字段个数不一样.现在想根据id idcard phone 在5张表内查数据比如 想查5张表内 id为1的数据全列出来新手提问...语句怎么写

解决方案 »

  1.   

    用union来做查询
    比如
    t1 (id, name, c1)
    t2 (id, name, c2)
    select *  from (select id, name, c1 col from t1
    union all select id, name, c2 col from t2 ) where id = 1
      

  2.   

    用union all来查,union会去重复行。
      

  3.   

    union all
    或者用动态SQL
      

  4.   

    用union all 来做查询 
    比如 
    t1 (id, name, c1) 
    t2 (id, name, c2) 
    t3 (id, name, c2) 
    t4 (id, name, c2) 
    t5 (id, name, c2) 
    select *  from (select id, name, c1 col from t1 
    union all select id, name, c2 col from t2 
    union all select id, name, c2 col from t3 
    union all select id, name, c2 col from t4 
    union all select id, name, c2 col from t5 ) where id = 1 
    其他的你自己试一下
      

  5.   

    其实可以认为的增加一个显示字段看是哪个表中的数据,这样也不会出现重复的情况了,如
    select id, name, c1 col ,'t1' as Table from t1 
    union 
    select id, name, c2 col ,'t2' as Table from t2
      

  6.   

    union all(id,name,age,birthday,phone)
      

  7.   

    select * from 
    (
    select id ,idcard ,phone from tb1
    union all
    select id ,idcard ,phone from tb2
    union all
    select id ,idcard ,phone from tb3
    union all
    select id ,idcard ,phone from tb4
    union all
    select id ,idcard ,phone from tb5
    ) a 
    where id =1
      

  8.   

    oracle里 union和 union all 不一样?
      

  9.   

    能解释一下  union和union all的区别吗?  学习一下
      

  10.   

    我理解的是楼主要,一个id只有一行显示,这不能用Union all吧!