Solved

Concatenate string in MySQL update query

Posted on 2009-07-13
4
733 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 275 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 45

Assisted Solution

by:Kent Olsen
Kent Olsen earned 225 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

707 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