Join the two columns of the table and update the result

I have a table that has two columns, and I need to combine these two and update the first column with the result.
For example, suppose 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 to do it using SQL?

+6
source share
3 answers

Try this (for MySQL)

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

and this is for MS-SQL

 UPDATE your_table SET col1 =col1 || "." || col2 
+13
source

Hometasks?

I am using mysql:

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

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 
+2
source

Source: https://habr.com/ru/post/903100/


All Articles