Solved

Concatenate string in MySQL update query

Posted on 2009-07-13
4
719 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
  • 2
4 Comments
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 275 total points
Comment Utility
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 45

Assisted Solution

by:Kdo
Kdo earned 225 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Fore-Foreword Today (2016) Maxmind has a new approach to the distribution of its data sets.  This article may be obsolete.  Instead of using the examples here, have a look at the MaxMind API (https://www.maxmind.com/en/geolite2-developer-package). …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now