Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 23-05-2009
Member
 
Join Date: Apr 2009
Posts: 24
Post mysql update column with another column

I need MySQL instruction for copying/update-split with another column the data in the same line for several lines in a table.

If in first column data is 23, 56, 89 & column two is empty like below....

Orignal
row1 column1(23) : row2 column2();
row1 column1(56) : row2 column2();
row1 column1(89) : row2 column2();

Should Look like
row1 column1(23) : row2 column2(23);
row1 column1(56) : row2 column2(56);
row1 column1(89) : row2 column2(89);
Reply With Quote
  #2  
Old 23-05-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: mysql update column with another column

If you generate a stateCountryTable that has two fields for the preservation of the country and the only condition you can use the SQL below to accomplish that you are talking but to update the same table should I'm not sure how that will be solved. However, you may enter them all to select from this table with the stuff analyzed and duplicated in a table where you have two fields, one for the condition and one for the country.

INSERT INTO stateCountryTable SELECT SUBSTRING(OriginalFieldName,1,2) as country,SUBSTRING(CategoryName,4,2) as state FROM originalTable;

as descriptive above, alternative you can copy you the table structure to give you a new name, delete you the existing country State range in the new table, only one structure without data therein. Then an inquiry like above, but enumerate all fields out and can do it in the order of the fields in the new table.
Reply With Quote
  #3  
Old 23-05-2009
Member
 
Join Date: May 2008
Posts: 2,008
Re: mysql update column with another column

Update column in a table whose values are not found in another table.

UPDATE TABLE_1 LEFT JOIN TABLE_2 ON TABLE_1.COLUMN_1= TABLE_2.COLUMN_2
SET TABLE_1.COLUMN = EXPR WHERE TABLE_2.COLUMN2 IS NULL

An outer joins is made based on the state of equijoin. Entries that do not match the equijoin from table2 are marked with the position of minimum signal.

This facilitates the actualization Tabelle1 column with expression, whose appropriate value from Tabelle2 is returned as ZERO
Reply With Quote
  #4  
Old 23-05-2009
Member
 
Join Date: May 2008
Posts: 2,293
Re: mysql update column with another column

It is not necessary loop by the means of the table, the development colonne2 = column1 references of the line which is currently in the course of treatment by selecting your declaration.

UPDATE <TABLE> SET Column2 = Column1

Just use update <your_table> set column2 = column1. That will place the values in column 1 into column 2.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "mysql update column with another column"
Thread Thread Starter Forum Replies Last Post
Find The Value of one column in another column Charth Windows Software 3 23-02-2011 03:01 AM
How to highlight identical cell value of one column in another column? D_chapple Windows Software 3 09-12-2009 01:11 PM
Mysql error message "Unknown column in on clause" Carnie Software Development 3 21-11-2009 11:03 AM
MySQL Error: BLOB/TEXT Column Used in Key Specification Balgovind Software Development 4 23-05-2009 09:59 AM
Getting the MAX value from a column rupak Software Development 4 31-01-2009 11:36 AM


All times are GMT +5.5. The time now is 12:40 PM.