Afficher un message
Vieux 18/08/2007, 21h43   #2
Gary Josack
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: New Value From Concatenated Values?

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)

  Réponse avec citation
 
Page generated in 0,04486 seconds with 9 queries