简体   繁体   English

MYSQL:将SELECT结果中的多个结果插入表中

[英]MYSQL: Inserting multiple results from SELECT results into a table

How do I insert the results of multiple rows of results into MYSQL? 如何将多行结果插入MYSQL?

My SQL results are : 我的SQL结果是:

user_id |   Name   | Age
--------+----------+-----
      1 | Rob      | 23
      2 | Jenny    | 35
      3 | Brock    | 18
      4 | Samantha | 46

How do I insert all the results into another SQL table? 如何将所有结果插入另一个SQL表? I'm guessing there is a "foreach row as ...." php function. 我猜有一个“ foreach行为...。”的PHP函数。 I am using Zend Framework. 我正在使用Zend Framework。

INSERT INTO tbl (user_id, name, age)
     SELECT user_id,
            name,
            age
       FROM tbl2
      WHERE ...

This can be done without involving PHP much. 无需太多涉及PHP即可完成此操作。 Most databases can handle that themselves: 大多数数据库可以自己处理:

INSERT INTO second_table (user_id, Name, Age)
   SELECT user_id, Name, Age
   FROM first_table

Here's the Mysql info on it: http://dev.mysql.com/doc/refman/5.1/de/insert-select.html 这是关于它的Mysql信息: http : //dev.mysql.com/doc/refman/5.1/de/insert-select.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM