1

I am trying to update user information (phone number) but mysql showing syntax error.

Here is the query for showing all data (phone number)

select distinct a.phone
from users u
join updated_phone a on a.phone like concat(u.phone_no, '%')
where u.phone_no like '88%'

This query works fine.

Here is the query for updating phone number in users table

UPDATE u
SET u.phone_no=a.phone
FROM      updated_phone as a 
JOIN      users as u
         on a.phone like concat(u.phone_no, '%')
         where u.phone_no like '88%'

But this update query throwing error in syntax near FROM and not updating values. How to solve this syntax error and update information?

1 Answer 1

2

You shouldn't use from in update because the updating table is already defined in the UPDATE clause.

 UPDATE users as u
 JOIN   updated_phone as a    on a.phone like 'u.phone_no%'
 SET u.phone_no= a.phone
 where u.phone_no like '88%'
Sign up to request clarification or add additional context in comments.

7 Comments

I have update the answer .. with join before set and i have also changed the like concat
I tried it before ,query executed but not updating values. For better understanding my question is related to this post stackoverflow.com/questions/36953942/…
You want match the phone number but not if begin with '88' ... i have update the answer ..adding '%u.phone_no%'
Any way the sintax error is solved then the question you posted is solved the rest is be related to another question
Code i wrote in question is okay. I provided the link to understand what i really want. Error is gone but i am not getting desired output yet. Please have a look what makes this query return without updating values.
|

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.