<?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: How to write flexible INSERT and UPDATE statements in MySQL</title>
	<atom:link href="http://www.xaprb.com/blog/2006/02/21/flexible-insert-and-update-in-mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.xaprb.com/blog/2006/02/21/flexible-insert-and-update-in-mysql/</link>
	<description>Stay curious!</description>
	<lastBuildDate>Thu, 09 Feb 2012 09:56:43 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Cherri</title>
		<link>http://www.xaprb.com/blog/2006/02/21/flexible-insert-and-update-in-mysql/#comment-19727</link>
		<dc:creator>Cherri</dc:creator>
		<pubDate>Tue, 15 Nov 2011 21:19:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.xaprb.com/blog/?p=103#comment-19727</guid>
		<description>table1:
           a, b, c
          (1, 5, 3),
          (2, 5, 6),
          (3, 4, 9);
table2:
     d, e, f
    (1, 1, 1),
    (4, 4, 4),
    (5, 5, 5);

If we had these tables related. lets say that table1 has foreign key the column d of table2. And we had a joined table like:

SELECT a,b,c,table2.e 
FROM table1 
CROSS JOIN table2
where table1.b= table2.d; 

How can new values be inserted?</description>
		<content:encoded><![CDATA[<p>table1:<br />
           a, b, c<br />
          (1, 5, 3),<br />
          (2, 5, 6),<br />
          (3, 4, 9);<br />
table2:<br />
     d, e, f<br />
    (1, 1, 1),<br />
    (4, 4, 4),<br />
    (5, 5, 5);</p>
<p>If we had these tables related. lets say that table1 has foreign key the column d of table2. And we had a joined table like:</p>
<p>SELECT a,b,c,table2.e<br />
FROM table1<br />
CROSS JOIN table2<br />
where table1.b= table2.d; </p>
<p>How can new values be inserted?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marg</title>
		<link>http://www.xaprb.com/blog/2006/02/21/flexible-insert-and-update-in-mysql/#comment-19711</link>
		<dc:creator>Marg</dc:creator>
		<pubDate>Sat, 22 Oct 2011 22:26:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.xaprb.com/blog/?p=103#comment-19711</guid>
		<description>update table Rating&#039;s ratingdate+25 if stars &gt;=4

I don&#039;t think you can query and update the same table so I created rating2 table (has same data).

update rating
set ratingdate = (ratingdate+25)
where stars = select avg(rating2.stars)
from rating2

Any advice would be appreciated asap.
Table: Rating
rID	mID	stars	ratingDate
201	101	2	2011-01-22
201	101	4	2011-01-27
202	106	4	Null
203	103	2	2011-01-20
203	108	4	2011-01-12
203	108	2	2011-01-30
204	101	3	2011-01-09
205	103	3	2011-01-27
205	104	2	2011-01-22
205	108	4	Null
206	107	3	2011-01-15
206	106	5	2011-01-19
207	107	5	2011-01-20
208	104	3	2011-01-02</description>
		<content:encoded><![CDATA[<p>update table Rating&#8217;s ratingdate+25 if stars &gt;=4</p>
<p>I don&#8217;t think you can query and update the same table so I created rating2 table (has same data).</p>
<p>update rating<br />
set ratingdate = (ratingdate+25)<br />
where stars = select avg(rating2.stars)<br />
from rating2</p>
<p>Any advice would be appreciated asap.<br />
Table: Rating<br />
rID	mID	stars	ratingDate<br />
201	101	2	2011-01-22<br />
201	101	4	2011-01-27<br />
202	106	4	Null<br />
203	103	2	2011-01-20<br />
203	108	4	2011-01-12<br />
203	108	2	2011-01-30<br />
204	101	3	2011-01-09<br />
205	103	3	2011-01-27<br />
205	104	2	2011-01-22<br />
205	108	4	Null<br />
206	107	3	2011-01-15<br />
206	106	5	2011-01-19<br />
207	107	5	2011-01-20<br />
208	104	3	2011-01-02</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Billy</title>
		<link>http://www.xaprb.com/blog/2006/02/21/flexible-insert-and-update-in-mysql/#comment-19581</link>
		<dc:creator>Billy</dc:creator>
		<pubDate>Sat, 20 Aug 2011 17:05:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.xaprb.com/blog/?p=103#comment-19581</guid>
		<description>I met a similar problem which got me thinking and researching all the day.

My situation like this: I got sales reports from two channels. Both of them have same format: product_id, sales_volume, month

What I need to do is to import these csv files and combine them into a single report: product_id, channel1_sale, chanel2_sale, month.

There are lots of products. Channel 1 and channel 2 may have same and different products.

I finally use your solution of &quot;Inserting new rows and updating existing rows&quot; to solve it. Additionally I made another temp table with one additional field to judge if the data comes from channel 1 or 2. 

At first I import to temp table, then I use your method to transfer data from temp data to final table, then I truncate the dump table.

It works like a charm!

Thank you Xaprb, your article really rocks even it was written years ago!</description>
		<content:encoded><![CDATA[<p>I met a similar problem which got me thinking and researching all the day.</p>
<p>My situation like this: I got sales reports from two channels. Both of them have same format: product_id, sales_volume, month</p>
<p>What I need to do is to import these csv files and combine them into a single report: product_id, channel1_sale, chanel2_sale, month.</p>
<p>There are lots of products. Channel 1 and channel 2 may have same and different products.</p>
<p>I finally use your solution of &#8220;Inserting new rows and updating existing rows&#8221; to solve it. Additionally I made another temp table with one additional field to judge if the data comes from channel 1 or 2. </p>
<p>At first I import to temp table, then I use your method to transfer data from temp data to final table, then I truncate the dump table.</p>
<p>It works like a charm!</p>
<p>Thank you Xaprb, your article really rocks even it was written years ago!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MYSQL Update if data exists else insert &#124; 24/7 Software</title>
		<link>http://www.xaprb.com/blog/2006/02/21/flexible-insert-and-update-in-mysql/#comment-18273</link>
		<dc:creator>MYSQL Update if data exists else insert &#124; 24/7 Software</dc:creator>
		<pubDate>Sun, 09 May 2010 20:53:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.xaprb.com/blog/?p=103#comment-18273</guid>
		<description>[...] a link to how I did it.  Share This                 This entry was written by admin, posted on May 9, 2010 [...]</description>
		<content:encoded><![CDATA[<p>[...] a link to how I did it.  Share This                 This entry was written by admin, posted on May 9, 2010 [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shared Items - August 2, 2009 &#171; Jeetu&#8217;s Shared Memory</title>
		<link>http://www.xaprb.com/blog/2006/02/21/flexible-insert-and-update-in-mysql/#comment-16712</link>
		<dc:creator>Shared Items - August 2, 2009 &#171; Jeetu&#8217;s Shared Memory</dc:creator>
		<pubDate>Mon, 03 Aug 2009 03:38:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.xaprb.com/blog/?p=103#comment-16712</guid>
		<description>[...] How to write flexible INSERT and UPDATE statements in MySQL [...]</description>
		<content:encoded><![CDATA[<p>[...] How to write flexible INSERT and UPDATE statements in MySQL [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

