<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>multiple updates using a single query &#8211; lifeLinux: Linux Tips, Hacks, Tutorials, Ebooks</title>
	<atom:link href="https://lifelinux.com/tag/multiple-updates-using-a-single-query/feed/" rel="self" type="application/rss+xml" />
	<link>https://lifelinux.com</link>
	<description>All About Linux !</description>
	<lastBuildDate>Tue, 23 Nov 2010 10:07:13 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.5.3</generator>
	<item>
		<title>How To Make Multiple Updates Using A Single Query In MySQL</title>
		<link>https://lifelinux.com/how-to-make-multiple-updates-using-a-single-query-in-mysql/</link>
					<comments>https://lifelinux.com/how-to-make-multiple-updates-using-a-single-query-in-mysql/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 23 Nov 2010 07:52:16 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[multiple updates in mysql]]></category>
		<category><![CDATA[multiple updates in mysql with single query]]></category>
		<category><![CDATA[multiple updates using a single query]]></category>
		<category><![CDATA[update with single query]]></category>
		<guid isPermaLink="false">http://www.lifelinux.com/?p=21</guid>

					<description><![CDATA[<p>Q. How to make multiple updates using a single query in mysql ? A. Using CASE &#38; WHEN commands to solve it. As you might know it’s quite easy to make multiple INSERTs in a single query, like this: INSERT INTO table_name (field1, field2) VALUES ('value1', 'value2'), ('value3', 'value4'); However, for some strange reason you [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://lifelinux.com/how-to-make-multiple-updates-using-a-single-query-in-mysql/">How To Make Multiple Updates Using A Single Query In MySQL</a> appeared first on <a rel="nofollow" href="https://lifelinux.com">lifeLinux: Linux Tips, Hacks, Tutorials, Ebooks</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p></p><p><span style="color: #ff0000;">Q</span>. How to make multiple updates using a single query in mysql ?</p>
<p><span style="color: #0000ff;">A</span>. Using CASE &amp; WHEN commands to solve it.<span id="more-21"></span></p>
<p>As you might know it’s quite easy to make multiple INSERTs in a single query, like this:</p>
<pre>INSERT INTO table_name (field1, field2) VALUES
('value1', 'value2'),
('value3', 'value4');
</pre>
<p><!--more-->However, for some strange reason you <strong>can’t</strong> do multiple changes to a table in a single Update query like this:</p>
<pre>UPDATE table_name
SET (field2 = 'valuex' WHERE field1 = 'value1'),
(field2='valuey' WHERE field1 = 'value3');
</pre>
<p>But, you can do a very interesting trick. You can combine an UPDATE with a CASE like this:</p>
<pre>UPDATE table_name SET field2 = CASE
WHEN field1 = 'value1' THEN 'valuex';
WHEN field1 = 'value3' THEN 'valuey';
ELSE field2
END;
</pre>
<p>The ELSE field2 is very important, otherwise you will overwrite the rest of the table with NULL.</p>
<g:plusone href="https://lifelinux.com/how-to-make-multiple-updates-using-a-single-query-in-mysql/" size="standard"  annotation="none"   ></g:plusone><p>The post <a rel="nofollow" href="https://lifelinux.com/how-to-make-multiple-updates-using-a-single-query-in-mysql/">How To Make Multiple Updates Using A Single Query In MySQL</a> appeared first on <a rel="nofollow" href="https://lifelinux.com">lifeLinux: Linux Tips, Hacks, Tutorials, Ebooks</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lifelinux.com/how-to-make-multiple-updates-using-a-single-query-in-mysql/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
