MAZ
MAZ

Reputation: 214

Update column with value from another column

In a SQL table I have two columns: the first contain a path and the second contains a value.

colunm1 /path/
colunm2 12345

I need to update the first column with the value that exists in the second column. to get this result :

colunm1 /path/12456/

I tried this, but not working

update tablename p
set p.colunm1 = "/path/'colunm2'/"

Upvotes: 0

Views: 484

Answers (2)

nbk
nbk

Reputation: 49410

You have to use CONCAT

update tablename p
set p.colunm1 = CONCAT("/path/",`colunm2`,"/");

Upvotes: 1

Mureinik
Mureinik

Reputation: 312344

You have the right idea, but the SQL you shared uses column2 as a string literal. You could use the concat to concatenate the two columns:

UPDATE tablename
SET    column1 = CONCAT(column1, column2)

Upvotes: 2

Related Questions