Solved

Copy data from one table to another in MySQL

Posted on 2014-09-14
5
205 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

744 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