Solved

Copy data from one table to another in MySQL

Posted on 2014-09-14
5
210 Views
Last Modified: 2014-09-17
Hi,

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.
0
Comment
Question by:Vipin Kumar
5 Comments
 
LVL 6

Accepted Solution

by:
Mandeep Singh earned 500 total points
ID: 40322468
Hi
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
0
 
LVL 1

Author Comment

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

Expert Comment

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

Author Comment

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

Expert Comment

by:Vimal DM
ID: 40323030
Hi,

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.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

813 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now