我想用现有表格上的查询结果填充表格。我怎么能这样做?
答案 0 :(得分:18)
(您不需要匹配表模式)
INSERT tbl_name (col1, col2)
SELECT value1, value2
FROM othertable
的参考资料
答案 1 :(得分:6)
答案 2 :(得分:4)
您甚至可以通过这种方式创建表,但列名必须匹配,或者将选择结果放入自动添加的列中:
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)