[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

MySQL:  Update Query help

Posted on 2014-07-16
5
Medium Priority
?
310 Views
Last Modified: 2014-07-21
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
0
Comment
Question by:detox1978
5 Comments
 
LVL 7

Expert Comment

by:Raghu Mutalikdesai
ID: 40198936
UPDATE likes SET likes.movie_id = movies.id FROM likes, movies WHERE likes.link_id = movies.link_id;

Open in new window

0
 
LVL 16

Expert Comment

by:Wasim Akram Shaik
ID: 40198946
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
 
LVL 2

Accepted Solution

by:
detox1978 earned 0 total points
ID: 40199009
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
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40199012
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
 
LVL 2

Author Closing Comment

by:detox1978
ID: 40208519
found solution online
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month19 days, 2 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question