8

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??

4 Answers 4

2

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 %';
Sign up to request clarification or add additional context in comments.

Comments

2

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'

Comments

2

This query works for me:

UPDATE users 
SET name = replace(name,'raj','rajesh')
WHERE name = 'raj'

1 Comment

If name like this `raj kumar rajan'?
0

Try this:

UPDATE users 
SET name = 'rajesh' 
WHERE name = 'raj';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.