从查询结果填充表(mysql)

从查询结果填充表(mysql),mysql,Mysql,我想用对现有表的查询结果填充一个表。我该怎么做 insert into table_name ... select * from table_name where .... 目标表和源查询的列数和数据类型必须匹配 请参见此图(不需要匹配表架构) 参见参考资料,您甚至可以通过这种方式创建表,尽管列名必须匹配,或者选择结果被放入自动添加的列中: mysql> create table foo ( id int primary key auto_increment, bar datetime

我想用对现有表的查询结果填充一个表。我该怎么做

insert into table_name ...
select * from table_name where ....
目标表和源查询的列数和数据类型必须匹配

请参见此图(不需要匹配表架构)


参见参考资料,您甚至可以通过这种方式创建表,尽管列名必须匹配,或者选择结果被放入自动添加的列中:

mysql> create table foo ( id int primary key auto_increment, bar datetime )
    -> select now() as bar, now() as baz from dual;
Query OK, 1 row affected, 1 warning (0.06 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> select * from foo;
+----+---------------------+---------------------+
| id | bar                 | baz                 |
+----+---------------------+---------------------+
|  1 | 2009-03-10 17:01:35 | 2009-03-10 17:01:35 |
+----+---------------------+---------------------+
1 row in set (0.00 sec)
插入tbl_名称(col1、col2)。。。可能有必要。
mysql> create table foo ( id int primary key auto_increment, bar datetime )
    -> select now() as bar, now() as baz from dual;
Query OK, 1 row affected, 1 warning (0.06 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> select * from foo;
+----+---------------------+---------------------+
| id | bar                 | baz                 |
+----+---------------------+---------------------+
|  1 | 2009-03-10 17:01:35 | 2009-03-10 17:01:35 |
+----+---------------------+---------------------+
1 row in set (0.00 sec)