[英]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.