SQL SERVERE数据库里有12张字段完全相同的表,如何同时在这12张表中查找条件相同的数据,求各位给条SQL句子吧

解决方案 »

  1.   

    select * from tb1 where 条件 = ...
    union all
    select * from tb2 where 条件 = ...
    ...
    select * from tb12 where 条件 = ...
      

  2.   

    select * from tb1 where 条件 = ...
    union all
    select * from tb2 where 条件 = ...
    ...
    select * from tb12 where 条件 = ...
    select * from 
    (
      select * from tb1
      union all
      select * from tb2
      ...
      select * from tb12
    ) t
    where 条件 = ...
      

  3.   

    select * from 
    (
      select * from tb1
      union all
      select * from tb2
      ...
      select * from tb12
    ) t
    where 条件 = ...
      

  4.   

    select * from 
    (
      select * from tb1
      union all
      select * from tb2
      ...
      select * from tb12
    ) t
    group by 字段1,字段2,...,字段1 having count(*)>1