• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 269
  • Last Modified:

Copy data from one table to another in MySQL


I want help in achieving the below two steps:

1. I want to copy data from my temporary table i.e. temp_table to another table i.e. actual_table.
temp_table consists of columns col1, col2, col3 and col4. While actual_table consists of columns accol1, accol2, accol3, accol4, accol5 and accol6. The data from all of temp_table columns needs to be copied in columns accol3, accol4, accol5 and accol6 of actual_table.

2. While the data is being copied from temp_table to actual_table, I also want set a specific value of accol2 in actual_table.

I hope I have provided inputs. If anything is required then do let me know.
Vipin Kumar
Vipin Kumar
1 Solution
Mandeep SinghDatabase AdministratorCommented:
Try this

INSERT INTO actual_table (accol3, accol4, accol5, accol6, accol2)
SELECT col1,col2,col3,col4,'accol2 value'
FROM temp_table

Open in new window

reference: stackoverflow.com/questions/7482443/how-to-copy-data-from-one-table-to-another-new-table-in-mysql
Vipin KumarSr. Network EngineerAuthor Commented:
will try and let you know.
Ramkisan JagtapLead DeveloperCommented:
what about the data in column accol1?
Vipin KumarSr. Network EngineerAuthor Commented:
it contains an auto incrementing int value
Vimal DMSenior Software EngineerCommented:

What Mandeep Singh said is correct and do not copy the auto incremented values from temp to actual table let the actual table be with its own id incremented.

If your copying auto incremented id, you will get into duplicate primary key issue and might other table mapping issues.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now