[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Concatenate string in MySQL update query

Posted on 2009-07-13
4
Medium Priority
?
744 Views
Last Modified: 2012-05-07
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
Comment
Question by:SaltyDawg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 1100 total points
ID: 24841446
You can use the CONCAT with separator like this:
update your_table
set field1 = concat_ws('_', field2, field3, field4);

Open in new window

0
 
LVL 46

Assisted Solution

by:Kent Olsen
Kent Olsen earned 900 total points
ID: 24841460
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
 
LVL 1

Author Comment

by:SaltyDawg
ID: 24841651
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
 
LVL 1

Author Closing Comment

by:SaltyDawg
ID: 31602905
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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question