Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL query - Add string before, after existing data

Tags:

mysql

I was wondering if someone is able to lend some wisdom about how to accomplish the following task in MySQL.

I need to run a query to add something inside a field before and after the existing data. For example, let's say I have the following data in 'characters.name':

'Fred Flintstone'
'Barney Rubble'

How would I insert something, in this example 'xxxxx' before the existing data 'Fred Flinstone' and also 'yyyyy' after the data?

The result would be:

'xxxxxFred Flintstoneyyyyy'
'xxxxxBarney Rubbleyyyyy'

Any assistance with this would be greatly appreciated.

Many thanks!

like image 634
green Avatar asked May 22 '12 14:05

green


1 Answers

SELECT CONCAT('xxxxx', name, 'yyyyy') AS name FROM characters
like image 140
eggyal Avatar answered Oct 23 '22 11:10

eggyal