SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru
    Join Date
    Sep 2008
    Posts
    977
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    update with join erroring

    I am trying to update on table with a sequence_number value from another table.

    It errors out. Please can anyone explain what I am overlooking?

    bazz

    query:
    Code MySQL:
    update page_blocks_stock
    set default_sequence = page_blocks_set.sequence_number
    FROM page_blocks_stock 
    INNER 
    JOIN 
    page_blocks_set 
    on page_blocks_set.page_block_name = page_blocks_stock.page_block_name
    WHERE page_blocks_set.business_id = 477
    and page_blocks_set.live_dev = 'live'
    and page_blocks_set.script_name = 'default'

    error msg
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM page_blocks_stock as pbs
    INNER
    JOIN
    page_blocks_set as pbset
    on pbset' at line 3

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    As far as I know, you can't use JOIN in an update statement: MySQL :: MySQL 5.1 Reference Manual :: 12.2.10 UPDATE Syntax

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,250
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    sure you can
    Quote Originally Posted by da page you linked to
    The preceding example shows an inner join that uses the comma operator, but multiple-table UPDATE statements can use any type of join permitted in SELECT statements, such as LEFT JOIN.
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,250
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    bazz, you can't say SET FROM
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by r937 View Post
    sure you can
    Oops...

  6. #6
    SitePoint Guru
    Join Date
    Sep 2008
    Posts
    977
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks to you both.


Bookmarks

Posting Permissions

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