SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    $books++ == true matsko's Avatar
    Join Date
    Sep 2004
    Location
    Toronto
    Posts
    795
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multiple Updates

    Lets say you have one table, but you want to update three values for three ids.

    UPDATE table SET value=100 WHERE id=1 LIMIT 1
    UPDATE table SET value=2200 WHERE id=2 LIMIT 1
    UPDATE table SET value=124240 WHERE id=3 LIMIT 1

    Is there a way to combine these things into a query that will update all them?
    I can't believe I ate the whole thing

  2. #2
    SitePoint Guru
    Join Date
    Jan 2004
    Location
    Uppsala, sverige
    Posts
    696
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Code:
    update table 
         set value = case id 
       when 1 then 100 
       when 2 then 2200
       when 3 then 124240 end
     where id in (1,2,3)


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
  •