1

I am trying to update a specific column in a table with data from the column of another table. I tried running the below command, but I am getting a syntax error at line 3.

UPDATE af_application af 
SET application_price=rss.application_price 
FROM rss_applications rss 
WHERE af.application_id=rss.application_id

2 Answers 2

4
UPDATE af_application af, rss_applications rss 
SET application_price=rss.application_price 
WHERE af.application_id=rss.application_id
Sign up to request clarification or add additional context in comments.

4 Comments

@David: is application_id covered with any index in rss_applications table? And how many rows are updated?
what do you mean by index? Are you referring to whether application_id is the primary key? If so application_id was set to be the primary key of the table. Only ~6000 records are updated.
@David: by saying index I mean dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html and dev.mysql.com/doc/refman/5.0/en/create-index.html. If it is already a PK - then yuo have nothing to do anymore. (except of adding af.application_price <> rss.application_price to your where condition.
Thanks for the links on indexes.
3

You can't use FROM in an UPDATE statement. You'll want to use JOIN instead.

UPDATE af_application af 
JOIN rss_applications rss 
ON af.application_id=rss.application_id
SET af.application_price=rss.application_price 

For more information, see http://dev.mysql.com/doc/refman/5.0/en/update.html and http://dev.mysql.com/doc/refman/5.0/en/join.html.

2 Comments

I tried your suggestion and I get a syntax error at line 3 JOIN...
@David - Sorry, I accidentally inverted SET and JOIN! I updated the answer. If it's slow, make sure that you have indexes on the application_id fields in both tables.

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.