Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql - How to update a column using another column's value plus some strings

Tags:

mysql

I have a table with the following column & value:

ColA = "8765" ColB = "2137"

I would like to update ColB in the same table to the following value:

ColC = "[8765][2137]"

How can I do it using phpmyadmin (meaning just sql syntax)?

like image 837
aeran Avatar asked Feb 09 '10 08:02

aeran


People also ask

How do you update a table column with another column's value?

UPDATE table SET col = new_value WHERE col = old_value AND other_col = some_other_value; UPDATE table SET col = new_value WHERE col = old_value OR other_col = some_other_value; As you can see, you can expand the WHERE clause as much as you'd like in order to filter down the rows for updating to what you need.

How Update same column with different values in MySQL?

MySQL UPDATE multiple columnsMySQL UPDATE command can be used to update multiple columns by specifying a comma separated list of column_name = new_value. Where column_name is the name of the column to be updated and new_value is the new value with which the column will be updated.


2 Answers

UPDATE table SET ColC = CONCAT("[", ColA, "][", ColB, "]"); 
like image 163
Select0r Avatar answered Oct 01 '22 09:10

Select0r


UPDATE     myTable SET     ColC = CONCAT('[', ColA, '][', ColB, ']') --WHERE... 
like image 36
David Hedlund Avatar answered Oct 01 '22 10:10

David Hedlund