两个表查询的结果要合成一个如何写sql
select id,name from table1
select id,name form table2
两个表,table1和table2都是类似结构,查询出来的sql如何写呢?

解决方案 »

  1.   

    这样??select   id,name   from   table1 union all
    select   id,name   form   table2 
      

  2.   


    去掉重复的:
    select       id,name       from       table1   
    union  
    select       id,name       form       table2   
    不去掉重复的:
    select       id,name       from       table1   
    union   all 
    select       id,name       form       table2   
      

  3.   

    select       id,name       from       table1   
    union   all 
    select       id,name       form       table2   此处需要注意,显示的列内容类型与数量要相同