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 开发者_如何学CmySQL 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.
精彩评论