在一个库中有多个表,其表的结构完全相同,我打算查询其中一个表的sn列,将它的结构显示到一个数据集中
例如:我有四个表名a1,a2,a3,a4,结构都是: 姓名,年纪,身高
我要求查询四个表中     包括姓名为"张三"的  姓名,年纪,身高,注意仅要显示3个字段为结果

解决方案 »

  1.   

    select * from
    (
    select * from a1
    union 
    select * from a2
    union
    select * from a3
    union 
    select * from a4
    ) T
    where name like '%张三%'
      

  2.   

    select 姓名,年纪,身高 from a1 where 姓名=‘张三’union
    select 姓名,年纪,身高 from a2 where 姓名=‘张三’union
    select 姓名,年纪,身高 from a3 where 姓名=‘张三’union
    select 姓名,年纪,身高 from a4 where 姓名=‘张三’union
      

  3.   

    create view all_info
    as
    select * from a1
    union all
    select * from a2
    union all
    select * from a3
    union all
    select * from a4select *
    from all_info
    where 姓名='张三'
      

  4.   

    create view all_info
    as
    select * from a1
    union all
    select * from a2
    union all
    select * from a3
    union all
    select * from a4select *
    from all_info
    where 姓名='张三'