mysql联合不同的数据库但是相同的模式

时间:2012-07-16 06:06:48

标签: mysql union

如图片(phpmyadmin),我在数据库中有表 week1 表现在是空的。

我有另一个数据库具有完全相同的sql架构 w1moninside w1monoutside 但他们有价值观。

我想联合这两个并在第1周插入它们 我该怎么办? 我为其中一个表插入了图片,仅用于clearance.unoin,例如第一个,数据 对我来说已经足够了

感谢。

enter image description here

mysql> describe w1moninside.data;
+--------------+------------------+------+-----+---------+-------+
| Field        | Type             | Null | Key | Default | Extra |
+--------------+------------------+------+-----+---------+-------+
| sid          | int(10) unsigned | NO   | PRI | NULL    |       |
| cid          | int(10) unsigned | NO   | PRI | NULL    |       |
| data_payload | text             | YES  |     | NULL    |       |
+--------------+------------------+------+-----+---------+-------+
3 rows in set (0.01 sec)

2 个答案:

答案 0 :(得分:0)

Insert into week1 (column list)
select column list from dbname.w1moninside where...
union
select column list from dbname.w1monoutside where..

答案 1 :(得分:0)

Insert into week1.TableName (column list)
select column list from w1moninside.TableName where...
union
select column list from w1monoutside.TableName where