Dr. Atul Tiwari
Dr. Atul Tiwari

Reputation: 1085

How to update column text value with concatenation of multiple columns text values?

For e.g. my table structure is like

id(int, auto_increment), 
first_name(text), 
last_name(text), 
address(text), 
merged_content(text)

I have thousands of rows which have first_name, last_name and address entries already filled. I want to update concatenated text in merged_content. I know, how to do this in PHP, but updating thousands of records (apprx 30K) is very time consuming.

So, I was hoping if something like this can be achieved in MySql directly -

Update table_x set merged_content="<p>" + first_name + " " + last_name + "</p><p><b>Address -</b> " + address + "</p>"

Obviously the above query is wrong, and not working, but I couldn't even find anything else, that I could try.

Upvotes: 1

Views: 166

Answers (2)

Abhik Chakraborty
Abhik Chakraborty

Reputation: 44844

Mysql has built-in function called concat which you can use, something as

Update table_x 
set 
merged_content=
concat('<p>',first_name,' ',last_name,'</p><p><b>Address -</b> ',address,'</p>'); 

Upvotes: 3

Aswin Murugesh
Aswin Murugesh

Reputation: 11070

Concatenation operator in sql is not + . It s ||

Replace all the + with || to make the query work

Upvotes: 0

Related Questions