Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Mysql Query to copy columns between tables

Posted on 2014-08-12
3
Medium Priority
?
432 Views
Last Modified: 2014-08-12
I need to know how to copy the field data in a column from a populated mysql table, to an unpopulated mysql table.

Table1 - populated with rows
Columns - products_id, column_2, column_3 ...

Table2 - an empty table
Columns - products_id, column_A, column_B ...

I would like to mirror the Table1.product_id column over to Table2.product_id column

Is there a mysql query that would allow this to happen?
0
Comment
Question by:FourMat
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
Dan Craciun earned 2000 total points
ID: 40256130
Try this (untested):
INSERT INTO table2 (products_id) 
SELECT products_id FROM table1

Open in new window

It more or less should work like this: http://dev.mysql.com/doc/refman/5.1/en/insert-select.html

HTH,
Dan
0
 

Author Closing Comment

by:FourMat
ID: 40256266
Well, that was incredibly simple and I feel like an idiot for making it more complicated than it needed to be.  Thanks for the help!
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 40256538
Glad I could help!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month20 days, 20 hours left to enroll

810 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