How to update multiple rows with one single query
Posted
by xRobot
on Stack Overflow
See other posts from Stack Overflow
or by xRobot
Published on 2010-05-14T22:53:47Z
Indexed on
2010/05/14
23:04 UTC
Read the original article
Hit count: 331
I use Postgresql + PHP.
Say I have this table:
Books ( id, title, year )
and this array of titles in PHP:
$titles = array ("bible","kafka","Book of Eli");
now I want update all rows where the title is in the $titles array above.
So I need a query like this:
UPDATE books SET year = '2001-11-11' WHERE title is in $titles;
Is is possible with one single query ? Or do I need to use FOR loop ?
© Stack Overflow or respective owner