MySQL: Update Query help

Hi All,

I have two tables likes and movies

likes:  id, movie_id, link_id
movies:  id, link_id

I want to update all the likes.movie_id with the movie.id where the link_id's match


Many thanks
LVL 2
detox1978Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Raghu MutalikdesaiSenior Manager in a leading IT Services companyCommented:
UPDATE likes SET likes.movie_id = movies.id FROM likes, movies WHERE likes.link_id = movies.link_id;

Open in new window

0
Wasim Akram ShaikCommented:
you should try something like this

UPDATE t1
  SET t1.movie_id= t2.[id]
  FROM likes AS t1
  INNER JOIN movies AS t2
  ON t1.link_id= t2.[link_id]
0
detox1978Author Commented:
I found a sample of the proper syntax online here

UPDATE `Catalogue` 
INNER JOIN `Categories` 
  ON Catalogue.Category_ID = Categories.Category_ID 
  AND Categories.Category_Name = 'Bases'
SET `Visible` = '0' 

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
Whatever you want to do with these tables, the WHERE clause would contain this:

WHERE likes.link_id = movies.link_id

Since UPDATE is not an idempotent query, but creates no new rows, you can rerun the query repeatedly without any problems.  You might want to run two queries - one to SELECT and a separate one to UPDATE.  How many rows are in these tables?  Have you tried any code yet?  If so, please show us, thanks.
0
detox1978Author Commented:
found solution online
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.