你的位置:首页 > 软件开发 > 数据库 > Mysql的简单使用(三)

Mysql的简单使用(三)

发布时间:2016-05-17 19:00:03
接上文Mysql的简单使用(二)mysql中结构相同的两个表进行合并:(注意需要两个表的结构是一样的)有如下结构的两个表father和person。合并的步骤为:1.把person表和father表两个表进行联合输出到临时表tmp中。命令为:>create temporar ...

接上文Mysql的简单使用(二)

mysql中结构相同的两个表进行合并:(注意需要两个表的结构是一样的)

有如下结构的两个表father和person。

Mysql的简单使用(三)

合并的步骤为:

1.把person表和father表两个表进行联合输出到临时表tmp中。

命令为:>create temporary table tmp select * from person union select *from father;

Mysql的简单使用(三)

2.创建结果表,并创建主键。

命令为:>create table resu(name varchar(20) primary key,age int,high int,address varchar(20));

3.把临时表中重复数据过滤并写入resu。

命令为:>insert into resu(name,age,high,address) select distinct name,age,high,address from tmp;

Mysql的简单使用(三)

4.删除临时表tmp。

命令为:>drop table tmp;

Mysql的简单使用(三)

 

思考:①是否可以只用以下一个命令:>create table tmp select * from person union select *from father;来创建新表呢?

     ②以上两个表都是来自同一个数据库,那么来自不同数据库的两个表又该如何合并呢?

原标题:Mysql的简单使用(三)

关键词:MYSQL

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。