合并表中数据

转载请注明:

仰望高端玩家的小清新 http://www.cnblogs.com/luruiyuan/

 

创建一张新的表,其中的内容是 table1 和 table2 的内容的全部记录,并根据列 TSF Timestamp 进行排序:

create table test as (select * from table1.raw_data) union all (select * from table2.raw_data) order by `TSF Timestamp`;

使用 union all 时,如果 两张表有主键冲突的情况,则会被保留

create table test as (select * from table1.raw_data) union (select * from table2.raw_data) order by `TSF Timestamp`;

只使用 union 时,主键冲突时只保留一个表的记录,另一个表的记录会丢失。

另:注意列名中有空格时的写法。

posted @ 2017-04-08 22:25  仰望高端玩家的小清新  阅读(174)  评论(0编辑  收藏  举报