Click to See Complete Forum and Search --> : Multiple Row Update (Different WHERE clauses)


tgrk35
04-30-2008, 11:30 AM
Is there a way to consolidate this:

UPDATE `departments` (`number`,`name`,`area_of_responsibility`) VALUES (1501005,'University Ombuds',11001) WHERE `number` = 1501005 LIMIT 1;

UPDATE `departments` (`number`,`name`,`area_of_responsibility`) VALUES (1501005,'University Ombuds',11001) WHERE `number` = 1501005 LIMIT 1;

UPDATE `departments` (`number`,`name`,`area_of_responsibility`) VALUES (1501005,'University Ombuds',11001) WHERE `number` = 1501005 LIMIT 1;

...into one statements such as this:

UPDATE `departments` (`number`,`name`,`area_of_responsibility`) VALUES ((1501005,'University Ombuds',11001) WHERE `number` = 1501005),((1501005,'University Ombuds',11001) WHERE `number` = 1501005),((1501005,'University Ombuds',11001) WHERE `number` = 1501005);


Of course the values wouldn't all be the same, I'm just too lazy to piece together another statement with a different WHERE clause.

Ideas?

Thanks for any and all help :)

chazzy
04-30-2008, 11:49 AM
provide a more concrete example, as I don't see what you're trying to consolidate there.

also, as a comment, the use of that format for update, while it might work on mysql, doesn't work on other DBMS. you should probably stick w/ the ANSI standards.

tgrk35
04-30-2008, 12:07 PM
UPDATE `departments` (`number`,`name`,`area_of_responsibility`) VALUES (1501005,'University Ombuds',11001) WHERE `number` = 1501005 LIMIT 1;

and

UPDATE `departments` (`number`,`name`,`area_of_responsibility`) VALUES (1516000,'Inst. Research & Planning',11001) WHERE `number` = 1516000 LIMIT 1;

consolidated into something like

UPDATE `departments` (`number`,`name`,`area_of_responsibility`) VALUES ((1501005,'University Ombuds',11001) WHERE `number` = 1501005), ((1516000,'Inst. Research & Planning`,11001) WHERE `number` = 1516000);

chazzy
04-30-2008, 12:15 PM
Nope. This is the full syntax for update, from mysql's website

http://dev.mysql.com/doc/refman/5.0/en/update.html