Update multiple rows with one query?

Posted by kavoir.com on Stack Overflow See other posts from Stack Overflow or by kavoir.com
Published on 2010-03-27T04:54:35Z Indexed on 2010/03/27 5:03 UTC
Read the original article Hit count: 332

Filed under:
|

I found something that works with updating one field at here: http://www.karlrixon.co.uk/articles/sql/update-multiple-rows-with-different-values-and-a-single-sql-query/

UPDATE person
    SET name = CASE id
        WHEN 1 THEN 'Jim'
        WHEN 2 THEN 'Mike'
        WHEN 3 THEN 'Precious'
    END
WHERE id IN (1,2,3)

My question is how to update more than one field? Such as:

UPDATE person
    SET name = CASE, sex = CASE id
        WHEN 1 THEN 'Jim', 'female'
        WHEN 2 THEN 'Mike' 'male'
        WHEN 3 THEN 'Precious', 'male'
    END
WHERE id IN (1,2,3)

Which doesn't work of course. Tried a few other combination and failed. Any idea? Thanks!

© Stack Overflow or respective owner

Related posts about mysql

Related posts about sql