Solved

Copy data from one table to another in MySQL

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
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…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

820 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