Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2011
    Posts
    32

    Unanswered: 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...

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    UPDATE node_revision 
    INNER
      JOIN node
        ON node.nid = node_revision.nid
       SET node_revision.comment = 2 
     WHERE node.type = 'ct_geography'
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jul 2011
    Posts
    32
    Awesome, nice breakdown of the query, it helped understand it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •