<?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>saait.com</title>
	<atom:link href="http://saait.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://saait.com</link>
	<description>Web development and more...</description>
	<lastBuildDate>Sat, 22 May 2010 16:20:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>To INSERT, or to UPDATE</title>
		<link>http://saait.com/2010/05/21/to-insert-or-to-update/</link>
		<comments>http://saait.com/2010/05/21/to-insert-or-to-update/#comments</comments>
		<pubDate>Fri, 21 May 2010 10:08:35 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://saait.com/?p=1</guid>
		<description><![CDATA[When I was trying to keep  some data from a table  A mirrored in an other table B, I was confronted with the issue:  what to do with rows that are already present in table B.  Do I have to check if they are already present and then do an UPDATE instead of an INSERT? [...]]]></description>
			<content:encoded><![CDATA[<p>When I was trying to keep  some data from a table  A mirrored in an other table B, I was confronted with the issue:  what to do with rows that are already present in table B.  Do I have to check if they are already present and then do an UPDATE instead of an INSERT? There must be an easier way. And there is, <strong><a href="http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html" target="_blank">INSERT &#8230; ON DUPLICATE KEY UPDATE</a>.</strong></p>
<p>The syntax is very straightforward:</p>
<pre class="brush: sql">
INSERT INTO table_b (id,title,body) VALUES (1,&#039;Title&#039;,&#039;Body&#039;)
ON DUPLICATE KEY UPDATE title=VALUES(title), body=VALUES(body);
</pre>
<p>In the example above, if table_b already has a row with the unique id value 1, this row is being updated with the new title and body.</p>
<p>It&#8217;s as easy as that, not two queries and if..else statement, but just one nice query.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://saait.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://saait.com/2010/05/21/to-insert-or-to-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!--array(34) {
  ["SERVER_SOFTWARE"]=>
  string(95) "Apache/1.3.37 (Unix) PHP/5.2.3 mod_ssl/2.8.28 OpenSSL/0.9.8a mod_perl/1.29 FrontPage/5.0.2.2510"
  ["REQUEST_URI"]=>
  string(6) "/feed/"
  ["DOCUMENT_ROOT"]=>
  string(41) "/home/saait/domains/saait.com/public_html"
  ["HTTP_ACCEPT"]=>
  string(83) "text/html,application/xhtml+xml,text/xml;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
  ["HTTP_ACCEPT_CHARSET"]=>
  string(30) "ISO-8859-1,utf-8;q=0.7,*;q=0.7"
  ["HTTP_ACCEPT_ENCODING"]=>
  string(4) "gzip"
  ["HTTP_ACCEPT_LANGUAGE"]=>
  string(14) "en-us,en;q=0.5"
  ["HTTP_CACHE_CONTROL"]=>
  string(8) "no-cache"
  ["HTTP_CONNECTION"]=>
  string(5) "close"
  ["HTTP_HOST"]=>
  string(9) "saait.com"
  ["HTTP_PRAGMA"]=>
  string(8) "no-cache"
  ["HTTP_USER_AGENT"]=>
  string(48) "CCBot/1.0 (+http://www.commoncrawl.org/bot.html)"
  ["HTTP_X_CC_ID"]=>
  string(8) "ccc02-01"
  ["PATH"]=>
  string(29) "/sbin:/usr/sbin:/bin:/usr/bin"
  ["REDIRECT_STATUS"]=>
  string(3) "200"
  ["REDIRECT_URL"]=>
  string(6) "/feed/"
  ["REMOTE_ADDR"]=>
  string(14) "38.107.179.217"
  ["REMOTE_PORT"]=>
  string(5) "41251"
  ["SCRIPT_FILENAME"]=>
  string(51) "/home/saait/domains/saait.com/public_html/index.php"
  ["SERVER_ADDR"]=>
  string(12) "89.18.176.59"
  ["SERVER_ADMIN"]=>
  string(19) "webmaster@saait.com"
  ["SERVER_NAME"]=>
  string(9) "saait.com"
  ["SERVER_PORT"]=>
  string(2) "80"
  ["SERVER_SIGNATURE"]=>
  string(61) "<ADDRESS>Apache/1.3.37 Server at saait.com Port 80</ADDRESS>
"
  ["GATEWAY_INTERFACE"]=>
  string(7) "CGI/1.1"
  ["SERVER_PROTOCOL"]=>
  string(8) "HTTP/1.1"
  ["REQUEST_METHOD"]=>
  string(3) "GET"
  ["QUERY_STRING"]=>
  string(0) ""
  ["SCRIPT_NAME"]=>
  string(10) "/index.php"
  ["PATH_TRANSLATED"]=>
  string(51) "/home/saait/domains/saait.com/public_html/index.php"
  ["PHP_SELF"]=>
  string(10) "/index.php"
  ["REQUEST_TIME"]=>
  string(10) "1329975044"
  ["argv"]=>
  array(0) {
  }
  ["argc"]=>
  string(1) "0"
}
-->
