Solved

need mysql command to copy/update one column with another column's data in the same row.

Posted on 2008-06-26
3
4,054 Views
Last Modified: 2009-12-19
This is probably pretty simple to do.  But, I need a mysql command to copy/update one empty column with another column's data in the same row for multiple rows in a table.

I need column1's data to copy over to column2 for multiple rows all in the same table ie.
Row1 column1 (some value)  column2 (no value)
Row2 column1 (some value)  column2 (no value)
Row3 column1 (some value)  column2 (no value)

to
Row1 column1 (some value)  column2 (some value)
Row2 column1 (some value)  column2 (some value)
Row3 column1 (some value)  column2 (some value)
0
Comment
Question by:allwebnow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
CoyotesIT earned 250 total points
ID: 21875835
Just use

update <your_table> set column2 = column1

That will place the values in column 1 into column 2

Good luck!
0
 
LVL 10

Expert Comment

by:bluefezteam
ID: 21875882
this will give you a start, not sure how to loop through in mySQL though

update tablename set column2 = (select column1 from tablename where column1 = row1) where column1 = row1

this will update the first row you need something like this though (pseudo code)

for i = 1 to [total number of records]
update tablename set column2 = (select column1 from tablename where column1 = i) where column1 = i
loop



0
 
LVL 8

Expert Comment

by:CoyotesIT
ID: 21875912
There is no need to loop through the table, setting the value column2 = column1 references the row that is currently being processed by your select statement. Although bluefezteam's method would work, it is unneccessary and more intense on your database.

UPDATE <TABLE> SET Column2 = Column1

is the method that will give you what you need without wasting resources

~CoyotesIT
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Suggested Solutions

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Introduction In this installment of my SQL tidbits, I will be looking at parsing Extensible Markup Language (XML) directly passed as string parameters to MySQL 5.1.5 or higher. These would be instances where LOAD_FILE (http://dev.mysql.com/doc/refm…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 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