简体   繁体   English

将 mySQL 行复制到具有不同名称的完全相同的表?

[英]Copy mySQL row to exact same table with different name?

I have two tables:我有两张桌子:

`temp_info` and `paid_info`

Upon successful payment, I want data from temp_info to be copied over to paid_info - exact same data, exact same field names, etc.成功付款后,我希望将temp_info中的数据复制到paid_info - 完全相同的数据、完全相同的字段名称等。

How can we go about doing this?我们怎么能做到这一点呢? Is there a more efficient way than doing a mySQL query and getting all of the temp_info details as variables and inserting them into the new table?有没有比执行 mySQL 查询并将所有 temp_info 详细信息作为变量并将它们插入到新表中更有效的方法?

The info in temp_info is defined with a unique ID, so we can use this to define it and copy the data over to the paid_info table. temp_info中的信息使用唯一 ID 定义,因此我们可以使用它来定义它并将数据复制到paid_info表中。

Thank you谢谢

Use INSERT INTO... SELECT syntax:使用INSERT INTO... SELECT语法:

http://dev.mysql.com/doc/refman/5.5/en/insert-select.html http://dev.mysql.com/doc/refman/5.5/en/insert-select.html

INSERT INTO paid_info (col1, col2, col3, ...)
SELECT s.col1, s.col2, s.col3, ...
FROM temp_info as s
WHERE s.unique_id = <some id that you want to copy over>

I suggest using INSERT-SELECT .我建议使用INSERT-SELECT

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

相关问题 完全相同的 MySQL 表结构/数据,相同查询的不同结果 - Exact Same MySQL Table Structure/Data, Different Result To Same Query MySQL 将表复制到具有相同凭据的不同数据库 - MySQL copy table to different database with same credentials 在特定表列上显示PHP在MySQL上的行内容(不同表上的.row名称相同) - Show MySQL row content on PHP from specific table column (same .row name on different tables) 如何使用PHP复制mysql行记录并将其以不同的ID保存在同一个表中 - How to copy a mysql row record and save it with different ID in same table using PHP Mysql同行拷贝 - 同一表120次 - Mysql same row copy-same table 120 times 无法将行复制到同一表(php-mysql) - Unable to copy a row to the same table(php-mysql) PHP MySQL 在同一个表中复制一行...使用主键和唯一键 - PHP MySQL Copy a row within the same table... with a Primary and Unique key 如何复制SQL表中的一行,将其插入同一表中,然后在名称末尾附加“ -Copy”? - How to copy a row in an SQL table, insert it into the same table, and append “-Copy” to the end of the name? 用相同的行但单元名称不同更新mysql表 - update mysql table with same row but different cell names 如何访问具有相同名称的多个mysql行的不同表 - How to access multiple mysql rows with same name different table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM