If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Update with different tables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-16-11, 00:38
ai_zaviour ai_zaviour is offline
Registered User
 
Join Date: Sep 2011
Posts: 53
Update with different tables

Hello Experts

I have a problem with update statement

I have two tables

MovieStar , StarsIn

MovieStar - name,address,birthdate,gender,rating
StarsIn - movieTitle,movieyear,starname,role

so I want to update the MovieStar - rating field

If StarsIn.role = 'Support'

Basically MovieStar.name and StarsIn.starname is the name of the actor

So if he act a supporting role the i want to update the rating+1

Any ideas

This was done by me..
But its wrong

update moviestar
set rating = rating+1
where moviestar.name=starsin.starname
and starsin.role = 'Support'
Reply With Quote
  #2 (permalink)  
Old 12-16-11, 06:21
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 620
Try this:

UPDATE moviestar m
JOIN starsin s ON m.name = s.starname
SET moviestar.rating = moviestar.rating+1;

and starsin.role = 'Support'
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
  #3 (permalink)  
Old 12-16-11, 07:20
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Code:
UPDATE moviestar 
INNER
  JOIN starsin  
    ON starsin.starname = moviestar.name
   AND starsin.role = 'Support'
   SET moviestar.rating = moviestar.rating+1
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On