Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Append and prepend text to a column

Tags:

sql

mysql

I need to append and prepend each value in a column called description with <p></p>

So I need to append each value with <p> and append with </p>

So the following test will become <p>test</p>.

Could anyone suggest a query that will handle this?

like image 354
Liam Fell Avatar asked Jan 14 '16 13:01

Liam Fell


2 Answers

UPDATE mytable SET description = CONCAT("<p>", description, "</p>")
like image 89
Martin Schneider Avatar answered Oct 03 '22 05:10

Martin Schneider


You can try like this:

update mytable
set col = '<p>' + col + '</p>';

or else you can use the CONCAT function like

update mytable
set col = CONCAT('<p>', col, '</p>')
like image 23
Rahul Tripathi Avatar answered Oct 03 '22 04:10

Rahul Tripathi