943,769 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 3055
  • MySQL RSS
Jan 28th, 2009
0

Move mysql colum to another table

Expand Post »
I have a column "ID" in a table, and I need to move that to another table in the same database. How do I do this?
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
desiguru is offline Offline
63 posts
since Aug 2006
Feb 3rd, 2009
0

Re: Move mysql colum to another table

Create ID column in second table
and run a update query on second table with joining both the tables,so all values in ID column will be update in second table properly
come back and drop column in the first table
Reputation Points: 22
Solved Threads: 9
Junior Poster in Training
varmadba is offline Offline
83 posts
since Jun 2008
Feb 3rd, 2009
0

Re: Move mysql colum to another table

Sorry how do you update only one column?
Last edited by desiguru; Feb 3rd, 2009 at 6:23 am.
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
desiguru is offline Offline
63 posts
since Aug 2006
Feb 4th, 2009
0

Re: Move mysql colum to another table

If you want to 'move' a column from one table to another table, both the tables should have a common column to link these 2 tables. First, as Vermadba has mentioned, you have to create a column called "id" in table_2 first. Then, update the second table's "id" column using joins.
For example,
mysql Syntax (Toggle Plain Text)
  1. UPDATE table_2,table_1 SET table_2.id=table_1.id WHERE table_1.counter = table_2.counter
This will update table_2's id column with id values of table_1.
Then delete the column "id" from table_1.
Cheers,
Nav
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: What query do i need???
Next Thread in MySQL Forum Timeline: need help, please!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC