Copy data from one table to another in MySQL

Posted on 2014-09-14
Last Modified: 2014-09-17

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.
Question by:Vipin Kumar
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

Mandeep Singh earned 500 total points
ID: 40322468
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


Author Comment

by:Vipin Kumar
ID: 40322853
will try and let you know.
LVL 12

Expert Comment

by:Ramkisan Jagtap
ID: 40322890
what about the data in column accol1?

Author Comment

by:Vipin Kumar
ID: 40322919
it contains an auto incrementing int value

Expert Comment

by:Vimal DM
ID: 40323030

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.

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question