比如两个表 都有id, name现在想通过select把两个表的内容一起查出来,
比如table1
id  name
1   aaa
2   bbbtable2
id  name
2   ccc
3   cddd变成
id name
1   aaa
2   bbb
2   ccc
3   cddd就是把表二追加到表一后面,重复啥的都不管,如何写?

解决方案 »

  1.   


    select * from tb1 union all select * from tb2
      

  2.   

    union all   两个表内容直接合并union       两表内容合并,并过滤重复值
      

  3.   

    select * from table1
    union all--表结构一致(或者类型一致的列),如果要去掉两个表中的重复数据用union
    select * from table2
      

  4.   

    select * from tb1 union all select * from tb2
      

  5.   

    select id,name from tab1
    union all
    select id,name from tab2
      

  6.   

    select id,name from table1
    unin all
    select id,name from table2用union all 是返回所有行
    用union 则返回剔除重复后的所有行