<?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 ON DUPLICATE KEY INSERT</title>
	<atom:link href="http://webguru.org/2007/12/18/lamp/mysql-on-duplicate-key-insert/feed/" rel="self" type="application/rss+xml" />
	<link>http://webguru.org/2007/12/18/lamp/mysql-on-duplicate-key-insert/</link>
	<description>Bits of web-dev, travel and personal musings...</description>
	<lastBuildDate>Tue, 03 May 2011 04:15:05 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Paul</title>
		<link>http://webguru.org/2007/12/18/lamp/mysql-on-duplicate-key-insert/comment-page-1/#comment-6</link>
		<dc:creator>Paul</dc:creator>
		<pubDate>Sat, 05 Jan 2008 00:02:15 +0000</pubDate>
		<guid isPermaLink="false">http://webguru.org/2007/12/18/lamp/mysql-on-duplicate-key-insert/#comment-6</guid>
		<description>sorry split last sentence....amend

I guess (correct me if I’m wrong) I could have inserted that into the primary key and not used autoinc, but at least this WAY I kept the AtoInc as a clean easy to use value/index</description>
		<content:encoded><![CDATA[<p>sorry split last sentence&#8230;.amend</p>
<p>I guess (correct me if I’m wrong) I could have inserted that into the primary key and not used autoinc, but at least this WAY I kept the AtoInc as a clean easy to use value/index</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul</title>
		<link>http://webguru.org/2007/12/18/lamp/mysql-on-duplicate-key-insert/comment-page-1/#comment-5</link>
		<dc:creator>Paul</dc:creator>
		<pubDate>Fri, 04 Jan 2008 23:59:44 +0000</pubDate>
		<guid isPermaLink="false">http://webguru.org/2007/12/18/lamp/mysql-on-duplicate-key-insert/#comment-5</guid>
		<description>Hi Brian,

Firstly - sorry for confusion - was getting my head around ON DUPLICATE KEY for the first time

(I originally thought the AutoInc  ID WAS a possible unique key - appreciate your feedback - its good when the penny finally drops)

You have to generate a unique key on insert (and that&#039;s not an AutoInc Field)

My example was on a Link table. Questions - Responses (fixed list) - Sources(people)
The Questions , Responses  and Sources all have unique ID&#039;s
 
BUT I couldn&#039;t see how to make any of THESE unique fields, as the same questions, responses and sources occur more than once in the link table.

BUT - a combination of Question AND Source ID was unique
ie a particular Source has either responded to a Question - in which case update
or has not - in which case insert

my Link table now had a new field to hold a unique response (uni_rsp)
uni_rsp was made UNIQUE and was fed the id of the question and the source
uni_rsp=CONCAT(fk_id_qst_rsp,fk_id_src_rsp)

I guess (correct me if I&#039;m wrong) I could have inserted that into the primary key and not used autoinc

atb

Paul

but at least this was I kept the AtoInc as a clean easy to use value</description>
		<content:encoded><![CDATA[<p>Hi Brian,</p>
<p>Firstly &#8211; sorry for confusion &#8211; was getting my head around ON DUPLICATE KEY for the first time</p>
<p>(I originally thought the AutoInc  ID WAS a possible unique key &#8211; appreciate your feedback &#8211; its good when the penny finally drops)</p>
<p>You have to generate a unique key on insert (and that&#8217;s not an AutoInc Field)</p>
<p>My example was on a Link table. Questions &#8211; Responses (fixed list) &#8211; Sources(people)<br />
The Questions , Responses  and Sources all have unique ID&#8217;s</p>
<p>BUT I couldn&#8217;t see how to make any of THESE unique fields, as the same questions, responses and sources occur more than once in the link table.</p>
<p>BUT &#8211; a combination of Question AND Source ID was unique<br />
ie a particular Source has either responded to a Question &#8211; in which case update<br />
or has not &#8211; in which case insert</p>
<p>my Link table now had a new field to hold a unique response (uni_rsp)<br />
uni_rsp was made UNIQUE and was fed the id of the question and the source<br />
uni_rsp=CONCAT(fk_id_qst_rsp,fk_id_src_rsp)</p>
<p>I guess (correct me if I&#8217;m wrong) I could have inserted that into the primary key and not used autoinc</p>
<p>atb</p>
<p>Paul</p>
<p>but at least this was I kept the AtoInc as a clean easy to use value</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian</title>
		<link>http://webguru.org/2007/12/18/lamp/mysql-on-duplicate-key-insert/comment-page-1/#comment-3</link>
		<dc:creator>Brian</dc:creator>
		<pubDate>Wed, 02 Jan 2008 20:57:39 +0000</pubDate>
		<guid isPermaLink="false">http://webguru.org/2007/12/18/lamp/mysql-on-duplicate-key-insert/#comment-3</guid>
		<description>Paul - I&#039;m not sure why you would use this approach if you have an auto-incrementing pK.  If you don&#039;t know the pK and it is an autoinc value, then you are correct, it will always create a new record because you haven&#039;t included a key for comparison in the first part of the statement (ie. INSERT INTO primaryKey=XX, field=YY ).  Can you provide an example of the statement you&#039;re using?</description>
		<content:encoded><![CDATA[<p>Paul &#8211; I&#8217;m not sure why you would use this approach if you have an auto-incrementing pK.  If you don&#8217;t know the pK and it is an autoinc value, then you are correct, it will always create a new record because you haven&#8217;t included a key for comparison in the first part of the statement (ie. INSERT INTO primaryKey=XX, field=YY ).  Can you provide an example of the statement you&#8217;re using?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul</title>
		<link>http://webguru.org/2007/12/18/lamp/mysql-on-duplicate-key-insert/comment-page-1/#comment-2</link>
		<dc:creator>Paul</dc:creator>
		<pubDate>Sun, 30 Dec 2007 16:04:58 +0000</pubDate>
		<guid isPermaLink="false">http://webguru.org/2007/12/18/lamp/mysql-on-duplicate-key-insert/#comment-2</guid>
		<description>Hi Brian,

One thing that&#039;s been puzzling me using ON DUPLICATE KEY
as I mentioned above - still learning and would really appreciate some advice
Using ON DUPLICATE KEY requires you  create a record with a unique field value - and  I would have thought an AUTOINC ID field would suffice, but (as far as I can tell) it doesn&#039;t work.
Using just a primary key autoinc ON DUPLICATE KEY always inserts a new record rather than updating/inserting
I&#039;ve manage to create a unique value (luckily my data has a unique value combination (CONCAT) each time its created)
Q: Can you make ON DUPLICATE key work with just an Autoincrement Primary Key ID?</description>
		<content:encoded><![CDATA[<p>Hi Brian,</p>
<p>One thing that&#8217;s been puzzling me using ON DUPLICATE KEY<br />
as I mentioned above &#8211; still learning and would really appreciate some advice<br />
Using ON DUPLICATE KEY requires you  create a record with a unique field value &#8211; and  I would have thought an AUTOINC ID field would suffice, but (as far as I can tell) it doesn&#8217;t work.<br />
Using just a primary key autoinc ON DUPLICATE KEY always inserts a new record rather than updating/inserting<br />
I&#8217;ve manage to create a unique value (luckily my data has a unique value combination (CONCAT) each time its created)<br />
Q: Can you make ON DUPLICATE key work with just an Autoincrement Primary Key ID?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul</title>
		<link>http://webguru.org/2007/12/18/lamp/mysql-on-duplicate-key-insert/comment-page-1/#comment-1</link>
		<dc:creator>Paul</dc:creator>
		<pubDate>Mon, 24 Dec 2007 11:36:32 +0000</pubDate>
		<guid isPermaLink="false">http://webguru.org/2007/12/18/lamp/mysql-on-duplicate-key-insert/#comment-1</guid>
		<description>Is the use of the WHERE clause legal with ON DUPLICATE KEY? (NEW TO THIS)</description>
		<content:encoded><![CDATA[<p>Is the use of the WHERE clause legal with ON DUPLICATE KEY? (NEW TO THIS)</p>
]]></content:encoded>
	</item>
</channel>
</rss>

