-3

I need to update only one word in ful name .For exp. I have a name "Abc Cde LEF PQr".I want to replace Abc with Thg. I have used query to find names which contains Abc

SELECT * FROM `table` WHERE `name` LIKE '%Abc%'

Please help me to do next step to replace the word

  • 1
    So its always the first word you want to replace ? – Abhik Chakraborty Jun 04 '14 at 07:49
  • Duplicate: http://stackoverflow.com/questions/1876762/mysql-way-to-update-portion-of-a-string – Mark Miller Jun 04 '14 at 07:49
  • 1
    And just for future reference, if you googled `mysql replace` the first and second links would have sent you to the functions linked below by most of those who answered. I'm just saying that there was a little more room to try on your own before you asked this question. – Catalin Deaconescu Jun 04 '14 at 07:53

4 Answers4

1

try this

UPDATE table  SET column = REPLACE(column, 'abc', 'thg');
Ezhil
  • 996
  • 8
  • 13
1

Something like this:

UPDATE `table` 
SET name = REPLACE(name, 'Abc', 'Thg')
WHERE `name` LIKE '%Abc%'

Reference:

Arion
  • 31,011
  • 10
  • 70
  • 88
0

You can replace into the select query, it's not destructive for database data. Try :

SELECT
  REPLACE(field1, 'Abc', 'Thg')
FROM table
WHERE name LIKE '%Abc%'
Pete_Gore
  • 594
  • 1
  • 5
  • 20
0

You can use Replace Function

Try this

UPDATE table  SET name = REPLACE(name, 'abc', 'thg');
WHERE name LIKE '%Abc%'
Vignesh Kumar A
  • 27,863
  • 13
  • 63
  • 115