Ariyan
Ariyan

Reputation: 15158

Concat two table columns and update one with result

I have table that has two columns and I need to concatenate these two and update first column with result.
For example assume this is my table:

+----+-------+-------+
| id | col1  | col2  |
+----+-------+-------+
|  1 | text1 | text2 |
+----+-------+-------+
|  2 | text3 | text4 |
+----+-------+-------+

after concatenation my table should be:

+----+-------------+-------+
| id |    col1     | col2  |
+----+-------------+-------+
|  1 | text1.text2 | text2 |
+----+-------------+-------+
|  2 | text3.text4 | text4 |
+----+-------------+-------+

How can I do this using SQL?

Upvotes: 10

Views: 37576

Answers (3)

Sruit A.Suk
Sruit A.Suk

Reputation: 7263

with MS SQL Server 2014 I used it like this

UPDATE CANDIDATES 
SET NEW_ADDRESS_EN = CANDI_HOME_NO + ', ' + 
CANDI_VILLAGE + ', ' + CANDI_ROAD + ' Road, ' + CANDI_PROVINCE

Upvotes: 4

dani herrera
dani herrera

Reputation: 51655

Homeworks?

I asume mysql:

update table t
set col1 = concat( col1, '.', col2)

Upvotes: 4

Marco
Marco

Reputation: 57573

Try this (for MySQL)

UPDATE your_table
SET col1 = CONCAT_WS('.', col1, col2)

and this for MS-SQL

UPDATE your_table
SET col1 =col1 || "." || col2

Upvotes: 13

Related Questions