List:General Discussion« Previous MessageNext Message »
From:Gary Josack Date:August 18 2007 8:43pm
Subject:Re: New Value From Concatenated Values?
View as plain text  
Kebbel, John wrote:
> Is there a way to update a table so that a  column's values can be changed to a
> concatenation of two other column values? For instance, something like ... 
>
> UPDATE TABLE tablename SET colA = colB.colC;
>
>
>
>
>
>   
Is this what you're looking for?

mysql> create table concattest (
    -> field1 varchar(25),
    -> field2 varchar(25),
    -> field3 varchar(25)
    -> );
Query OK, 0 rows affected (0.07 sec)

mysql> insert into concattest (field2, field3) values ('hi', 'there');
Query OK, 1 row affected (0.00 sec)

mysql> select * from concattest;
+--------+--------+--------+
| field1 | field2 | field3 |
+--------+--------+--------+
| NULL   | hi     | there  |
+--------+--------+--------+
1 row in set (0.00 sec)

mysql> update concattest set field1 = concat(field2, field3);
Query OK, 1 row affected (0.03 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from concattest;
+---------+--------+--------+
| field1  | field2 | field3 |
+---------+--------+--------+
| hithere | hi     | there  |
+---------+--------+--------+
1 row in set (0.00 sec)

Thread
New Value From Concatenated Values?John Kebbel18 Aug
  • Re: New Value From Concatenated Values?Gary Josack18 Aug
Re: New Value From Concatenated Values?John Kebbel19 Aug