I want to replace a particular string in mysql database, i am using this query :
UPDATE users
SET name
=replace(name,'raj','rajesh')
however what this query does is where it find raj it will replaces by rajesh for e.g if there is a string raju in databse after running this query raju becomes rajeshu which i dont want. i want a query which matches the replace string exactly means after running a query only 'raj' should get replaced with 'rajesh' and 'raju' should remain as is.. can someone please help??
Remove characters from string using TRIM() TRIM() function is used to remove any character/ whitespace from the start/ end or both from a string.
If you are using MySQL Workbench, right click on the database schema and select "Search Table Data..." then fill out the form. This will search the entire database.
Try below query to replace raj
with rajesh
update users set name=replace(name,' raj ',' rajesh ');
OR
update users set name=replace(name,'raj ','rajesh ') where name like '% raj %';
Try this it will definitely work for you.
update users
set name=replace(LOWER(name),'raj','rajesh')
where
name like 'raj %'
OR
name like '% raj %'
OR
name = 'raj'
This query works for me:
UPDATE users
SET name = replace(name,'raj','rajesh')
WHERE name = 'raj'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With