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 > Updating based on a field in a different table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-26-11, 02:47
akrashdi akrashdi is offline
Registered User
 
Join Date: Jul 2011
Posts: 8
Updating based on a field in a different table

Hi,

I am having trouble figuring out how to update values of many records in a table.

node (table)
nid
type
comment

node_revision (table)
nid
comment

I wanna do something like:
Code:
UPDATE node_revision SET node_revision.comment=2 WHERE node.nid = node_revision.nid AND node.type='ct_geography'
I mean `node_revision` table does not have 'type' column, but `node` table has it. How do I update `node_revision` based on `node` field?

Appreciated...
Reply With Quote
  #2 (permalink)  
Old 09-26-11, 04:38
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Code:
UPDATE node_revision 
INNER
  JOIN node
    ON node.nid = node_revision.nid
   SET node_revision.comment = 2 
 WHERE node.type = 'ct_geography'
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 09-26-11, 06:17
akrashdi akrashdi is offline
Registered User
 
Join Date: Jul 2011
Posts: 8
Awesome, nice breakdown of the query, it helped understand it.
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