• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 749
  • Last Modified:

Concatenate string in MySQL update query

I need to update all the fields in table based on other fields

field1 = field2 + "_" + field3 + "_" + field4

I have have the use of CONCAT but not sure how to use it.

Thanks
0
SaltyDawg
Asked:
SaltyDawg
  • 2
2 Solutions
 
Kevin CrossChief Technology OfficerCommented:
You can use the CONCAT with separator like this:
update your_table
set field1 = concat_ws('_', field2, field3, field4);

Open in new window

0
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi SaltyDawg,

Exactly which concatenation operator you can use depends on the SQL parser settings.  :)

Regardless of the shortcut, you can always call the CONCAT function.  Just list the items to be concatenated.

  CONCAT (field2, "_", field3, " ", field4);


Good Luck,
kent
0
 
SaltyDawgAuthor Commented:
Thanks
I actually used both concat_ws and CONCAT and orginally it did not work but I see my errors. I had quotes around my field names.
0
 
SaltyDawgAuthor Commented:
I shared your points. Since mwvisa1 responded first and i did use the concat_ws method I award him more points. Thanks to you both.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now