简体   繁体   中英

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.

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?

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.

Thank you

Use INSERT INTO... SELECT syntax:

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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