<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: MySQL: Update Multiple Rows or Records with One Single Query</title>
	<atom:link href="http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html/feed" rel="self" type="application/rss+xml" />
	<link>http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html</link>
	<description>Just another dumbass webmaster, goofing around...</description>
	<lastBuildDate>Wed, 08 Feb 2012 09:57:05 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Aaron</title>
		<link>http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html/comment-page-1#comment-15694</link>
		<dc:creator>Aaron</dc:creator>
		<pubDate>Thu, 10 Nov 2011 05:52:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html#comment-15694</guid>
		<description>Here&#039;s a much more efficient MySQL-flavored solution:

INSERT INTO tbl_name
 (pk_cols, update_cols)
VALUES
 (pk_vals, update_vals),
 ...
 (pk_vals, update_vals)
ON DUPLICATE KEY UPDATE
 update_col=VALUES(update_col),
 ...
 update_col=VALUES(update_col);

OPTIMIZE TABLE tbl_name;

Example as per article:
INSERT INTO categories
 (id, display_order, title)
VALUES
 (1, 3, &#039;New Title 1&#039;),
 (2, 4, &#039;New Title 2&#039;),
 (3, 5, &#039;New Title 3&#039;)
ON DUPLICATE KEY UPDATE
 display_order=VALUES(display_order),
 title=VALUES(title);

OPTIMIZE TABLE tbl_name;

The advantage of this solution is that it&#039;s driven by the indexing of the primary keys, on which a CASE cannot rely. The OPTIMIZE TABLE part is only advantageous when updating variable-length cells (i.e. VARCHAR, VARBINARY, BLOB, or TEXT). For multiple-column primary keys, you simply specify all of them in the statement.</description>
		<content:encoded><![CDATA[<p>Here&#8217;s a much more efficient MySQL-flavored solution:</p>
<p>INSERT INTO tbl_name<br />
 (pk_cols, update_cols)<br />
VALUES<br />
 (pk_vals, update_vals),<br />
 &#8230;<br />
 (pk_vals, update_vals)<br />
ON DUPLICATE KEY UPDATE<br />
 update_col=VALUES(update_col),<br />
 &#8230;<br />
 update_col=VALUES(update_col);</p>
<p>OPTIMIZE TABLE tbl_name;</p>
<p>Example as per article:<br />
INSERT INTO categories<br />
 (id, display_order, title)<br />
VALUES<br />
 (1, 3, &#8216;New Title 1&#8242;),<br />
 (2, 4, &#8216;New Title 2&#8242;),<br />
 (3, 5, &#8216;New Title 3&#8242;)<br />
ON DUPLICATE KEY UPDATE<br />
 display_order=VALUES(display_order),<br />
 title=VALUES(title);</p>
<p>OPTIMIZE TABLE tbl_name;</p>
<p>The advantage of this solution is that it&#8217;s driven by the indexing of the primary keys, on which a CASE cannot rely. The OPTIMIZE TABLE part is only advantageous when updating variable-length cells (i.e. VARCHAR, VARBINARY, BLOB, or TEXT). For multiple-column primary keys, you simply specify all of them in the statement.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Col SC Sood (Retd)</title>
		<link>http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html/comment-page-1#comment-15573</link>
		<dc:creator>Col SC Sood (Retd)</dc:creator>
		<pubDate>Wed, 28 Sep 2011 14:57:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html#comment-15573</guid>
		<description>I used
UPDATE `table_name` SET `field_name` = CASE `id`
WHEN &#039;1&#039; THEN &#039;value_1&#039;
WHEN &#039;2&#039; THEN &#039;value_2&#039;
WHEN &#039;3&#039; THEN &#039;value_3&#039;
ELSE `field_name`
END

I am thrilled! Thanks a lot!!</description>
		<content:encoded><![CDATA[<p>I used<br />
UPDATE `table_name` SET `field_name` = CASE `id`<br />
WHEN &#8217;1&#8242; THEN &#8216;value_1&#8242;<br />
WHEN &#8217;2&#8242; THEN &#8216;value_2&#8242;<br />
WHEN &#8217;3&#8242; THEN &#8216;value_3&#8242;<br />
ELSE `field_name`<br />
END</p>
<p>I am thrilled! Thanks a lot!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark</title>
		<link>http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html/comment-page-1#comment-15568</link>
		<dc:creator>Mark</dc:creator>
		<pubDate>Mon, 26 Sep 2011 17:28:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html#comment-15568</guid>
		<description>As an alternative to an ELSE value, you can provide a WHERE clause:

UPDATE `table` SET `col` = CASE `id`
WHEN 1 THEN &#039;one&#039;
WHEN 2 THEN &#039;two&#039;
WHEN 3 THEN &#039;three&#039;
END
WHERE `id` IN (1, 2, 3)

Same result but without doing a no-op update no rows you don&#039;t care about.</description>
		<content:encoded><![CDATA[<p>As an alternative to an ELSE value, you can provide a WHERE clause:</p>
<p>UPDATE `table` SET `col` = CASE `id`<br />
WHEN 1 THEN &#8216;one&#8217;<br />
WHEN 2 THEN &#8216;two&#8217;<br />
WHEN 3 THEN &#8216;three&#8217;<br />
END<br />
WHERE `id` IN (1, 2, 3)</p>
<p>Same result but without doing a no-op update no rows you don&#8217;t care about.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vaibhav</title>
		<link>http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html/comment-page-1#comment-15476</link>
		<dc:creator>vaibhav</dc:creator>
		<pubDate>Fri, 29 Jul 2011 10:49:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html#comment-15476</guid>
		<description>no one is better user oracle 10i</description>
		<content:encoded><![CDATA[<p>no one is better user oracle 10i</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yang Yang</title>
		<link>http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html/comment-page-1#comment-14338</link>
		<dc:creator>Yang Yang</dc:creator>
		<pubDate>Thu, 17 Mar 2011 01:34:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html#comment-14338</guid>
		<description>The SQL is added at the end of the article.</description>
		<content:encoded><![CDATA[<p>The SQL is added at the end of the article.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rusty</title>
		<link>http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html/comment-page-1#comment-14179</link>
		<dc:creator>Rusty</dc:creator>
		<pubDate>Fri, 28 Jan 2011 11:34:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html#comment-14179</guid>
		<description>Have you benchmarked the CASE statement to see if it is actually better than the temporary table solution?

I&#039;d also be interested in how both solutions compare to just doing an INSERT ON DUPLICATE KEY UPDATE.</description>
		<content:encoded><![CDATA[<p>Have you benchmarked the CASE statement to see if it is actually better than the temporary table solution?</p>
<p>I&#8217;d also be interested in how both solutions compare to just doing an INSERT ON DUPLICATE KEY UPDATE.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JavaGenious</title>
		<link>http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html/comment-page-1#comment-11346</link>
		<dc:creator>JavaGenious</dc:creator>
		<pubDate>Wed, 08 Dec 2010 03:51:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html#comment-11346</guid>
		<description>Thanks for the info.

Can we write a single MySQL query to update multiple ID&#039;s inside the same table?</description>
		<content:encoded><![CDATA[<p>Thanks for the info.</p>
<p>Can we write a single MySQL query to update multiple ID&#8217;s inside the same table?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gary</title>
		<link>http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html/comment-page-1#comment-11223</link>
		<dc:creator>Gary</dc:creator>
		<pubDate>Tue, 09 Nov 2010 06:27:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html#comment-11223</guid>
		<description>Sorry I&#039;m a bit lost here - is your update method using CASE part of the original method (eg: creating a temporary table, inserting first) or is that a way to avoid a temporary table all together? Could you please provide the structure of the options table? Thanks a lot, I would appreciate it.</description>
		<content:encoded><![CDATA[<p>Sorry I&#8217;m a bit lost here &#8211; is your update method using CASE part of the original method (eg: creating a temporary table, inserting first) or is that a way to avoid a temporary table all together? Could you please provide the structure of the options table? Thanks a lot, I would appreciate it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yang Yang</title>
		<link>http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html/comment-page-1#comment-9910</link>
		<dc:creator>Yang Yang</dc:creator>
		<pubDate>Tue, 25 May 2010 04:07:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html#comment-9910</guid>
		<description>I think either type is fine with this approach.</description>
		<content:encoded><![CDATA[<p>I think either type is fine with this approach.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Colin Bodkin</title>
		<link>http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html/comment-page-1#comment-9908</link>
		<dc:creator>Colin Bodkin</dc:creator>
		<pubDate>Mon, 24 May 2010 15:11:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html#comment-9908</guid>
		<description>I am using MySQL 5.0.  Do the databases need to be of a certain type (MyISAM, InnoDB) for this to work?</description>
		<content:encoded><![CDATA[<p>I am using MySQL 5.0.  Do the databases need to be of a certain type (MyISAM, InnoDB) for this to work?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cheers!!!!!</title>
		<link>http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html/comment-page-1#comment-9886</link>
		<dc:creator>cheers!!!!!</dc:creator>
		<pubDate>Mon, 17 May 2010 08:43:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html#comment-9886</guid>
		<description>we have been fighting the slow sql update problem for days now,

your solution was quick to implement and works like a charm.

thanks!!!!</description>
		<content:encoded><![CDATA[<p>we have been fighting the slow sql update problem for days now,</p>
<p>your solution was quick to implement and works like a charm.</p>
<p>thanks!!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: AgDude</title>
		<link>http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html/comment-page-1#comment-9789</link>
		<dc:creator>AgDude</dc:creator>
		<pubDate>Fri, 16 Apr 2010 13:29:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html#comment-9789</guid>
		<description>Excellent Tip!  It seems really simple now that I see it, but I have been using a lot of slow loops for a long time.  Thanks.</description>
		<content:encoded><![CDATA[<p>Excellent Tip!  It seems really simple now that I see it, but I have been using a lot of slow loops for a long time.  Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marty Jongepier</title>
		<link>http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html/comment-page-1#comment-9461</link>
		<dc:creator>Marty Jongepier</dc:creator>
		<pubDate>Fri, 26 Mar 2010 22:18:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html#comment-9461</guid>
		<description>Excellent! Took me long to find this, have been pulling my hair out for days until I found this! Thank you!</description>
		<content:encoded><![CDATA[<p>Excellent! Took me long to find this, have been pulling my hair out for days until I found this! Thank you!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yang Yang</title>
		<link>http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html/comment-page-1#comment-8214</link>
		<dc:creator>Yang Yang</dc:creator>
		<pubDate>Fri, 26 Feb 2010 09:53:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html#comment-8214</guid>
		<description>Nice!</description>
		<content:encoded><![CDATA[<p>Nice!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: charles caadlawon</title>
		<link>http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html/comment-page-1#comment-8112</link>
		<dc:creator>charles caadlawon</dc:creator>
		<pubDate>Tue, 16 Feb 2010 05:38:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.kavoir.com/2009/05/mysql-update-multiple-rows-with-one-single-query.html#comment-8112</guid>
		<description>hello i want to ask if how can i able to update one single row in different tables. i use php and mysql as my repository</description>
		<content:encoded><![CDATA[<p>hello i want to ask if how can i able to update one single row in different tables. i use php and mysql as my repository</p>
]]></content:encoded>
	</item>
</channel>
</rss>

