<?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>devexp &#187; select</title>
	<atom:link href="http://www.devexp.eu/tag/select/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.devexp.eu</link>
	<description>DEVelopment EXPerience, shared with the world!</description>
	<lastBuildDate>Tue, 16 Feb 2010 14:38:17 +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>forgotten syntaxes for MySQL</title>
		<link>http://www.devexp.eu/2009/03/31/forgotten-syntaxes-for-mysql/</link>
		<comments>http://www.devexp.eu/2009/03/31/forgotten-syntaxes-for-mysql/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 11:25:26 +0000</pubDate>
		<dc:creator>van Rumste Kenneth</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[delayed]]></category>
		<category><![CDATA[duplicate key]]></category>
		<category><![CDATA[infile]]></category>
		<category><![CDATA[insert]]></category>
		<category><![CDATA[option]]></category>
		<category><![CDATA[outfile]]></category>
		<category><![CDATA[replace]]></category>
		<category><![CDATA[select]]></category>
		<category><![CDATA[syntax]]></category>
		<category><![CDATA[update]]></category>

		<guid isPermaLink="false">http://www.devexp.eu/?p=527</guid>
		<description><![CDATA[A lot of people seem to have problems with updating or inserting data in tables in an intelligent way. We shouldn't point a finger to those who don’t use the correct syntax for the problem it solves, because there are a lot of different ways to do this, but I wanted to create a little [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright" style="border: 0pt none; margin: 5px;" title="MySQL" src="http://dev.mysql.com/common/logos/logo_mysql_sun_a.gif" alt="" width="114" height="68" />A lot of people seem to have problems with updating or inserting data in tables in an intelligent way. We shouldn't point a finger to those who don’t use the correct syntax for the problem it solves, because there are a lot of different ways to do this, but I wanted to create a little list of interesting syntax's that are often forgotten and never used. I will talk about:</p>
<ul>
<li>insert... on duplicate key update</li>
<li>replace</li>
<li>insert... select</li>
<li>Load data infile and select into outfile</li>
<li>delayed</li>
</ul>
<p><span id="more-527"></span></p>
<p>When starting with SQL a few years ago I always executed a query to get a row out of a table and then updated or insert a row in a second query. Of course there are better solutions for this problem according to the specific action you want to do:</p>
<p><strong>INSERT... ON DUPLICATE KEY UPDATE</strong><br />
In this case it is possible for anyone to insert a row in a table, but if the key of this row already exists, it updates a specific value:</p>
<pre class="brush: sql;">INSERT INTO table (a,b,c) VALUES (1,2,3) ON DUPLICATE KEY UPDATE c=c+1;</pre>
<p><strong>REPLACE</strong><br />
Replace works exactly like insert, except that if a row already exists, for the unique index or primary key, it is first deleted and then inserted as a new row.<br />
If you have a table where there is no primary key or index, the replace statement makes absolutely no sense, as there will be nothing to delete.</p>
<pre class="brush: sql;">REPLACE INTO table_1 SET a=1, b=2;</pre>
<p>The difference between on duplicate key and replace is:<br />
‘Insert … on duplicate key update’ does an insert or an update.<br />
‘Replace’ does and insert with a possible delete first.</p>
<p><strong>INSERT … SELECT</strong><br />
This will insert rows from one or more tables into another table quickly, again to avoid the fact that you should write to queries to execute this.<br />
Use ‘ignored’ in the syntax to ignore duplicate-key violations</p>
<p><strong>LOAD DATA INFILE and SELECT … INTO OUTFILE</strong><br />
‘Load data infile’ will read data from a file into table at very high speed and ‘select into outfile’ will do the exact opposite, writing data from a table to a file.</p>
<p><strong>DELAYED</strong><br />
When you have users on your application that don’t have the time to wait this is a very handy option for the insert statement. It is generally known that the insert statement takes a lot of time during the execution of it, and with this option you can create the opportunity for your user to directly go on with other actions. The insert will only be queued until the table isn’t being used by another thread. Another benefit is that huge inserts can be executed at once and this will result in a much faster execution time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devexp.eu/2009/03/31/forgotten-syntaxes-for-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Select element, return 2 values</title>
		<link>http://www.devexp.eu/2009/01/30/select-element-return-2-values/</link>
		<comments>http://www.devexp.eu/2009/01/30/select-element-return-2-values/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 10:53:22 +0000</pubDate>
		<dc:creator>van Rumste Kenneth</dc:creator>
				<category><![CDATA[Jquery]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[element]]></category>
		<category><![CDATA[option]]></category>
		<category><![CDATA[return]]></category>
		<category><![CDATA[select]]></category>
		<category><![CDATA[values]]></category>

		<guid isPermaLink="false">http://www.devexp.eu/?p=340</guid>
		<description><![CDATA[I had a problem earlier today: I needed to have a select box that returns 2 or more values in stead of 1. I got this far: The value of the options gets the id of the item that is displayed in each option. I do have an other value that should be linked on [...]]]></description>
			<content:encoded><![CDATA[<p>I had a problem earlier today: I needed to have a select box that returns 2 or more values in stead of 1.<br />
I got this far:<br />
The value of the options gets the id of the item that is displayed in each option.<br />
I do have an other value that should be linked on this option. Is there an easy way to do this?</p>
<pre class="brush: xml;">
&lt;select id=&quot;category&quot; name=&quot;data[cat]&quot;&gt;
    &lt;option label=&quot;0&quot; value=&quot;12&quot;&gt;A&lt;/option&gt;
    &lt;option label=&quot;0&quot; value=&quot;7&quot;&gt;B&lt;/option&gt;
&lt;/select&gt;
</pre>
<p>I tried to do this with entering the second value into a label attribute but then the problem is that i don't know the correct way to get the label value of the selected option. This is written in Jquery.<br /> To get the selected option I use:</p>
<pre class="brush: jscript;">
$(&quot;#category&quot;).livequery('change', function () {
var catId = ($(this)[0].value);
});
</pre>
<p>the solution seems to be quite simple:</p>
<p>The label attribute is used by some browsers to display the content of the option, so your list box might display two 0 options.</p>
<p>A better solution might be to do the following:</p>
<pre class="brush: xml;">
&lt;select id=&quot;category&quot; name=&quot;data[cat]&quot;&gt;
    &lt;option value=&quot;12,0&quot;&gt;A&lt;/option&gt;
    &lt;option value=&quot;7,0&quot;&gt;B&lt;/option&gt;
&lt;/select&gt;
</pre>
<p>and split the value in the event handler, e.g.</p>
<pre class="brush: jscript;">
$(&quot;#category&quot;).livequery('change', function () {
    var values = ($(this)[0].value).split(&quot;,&quot;);
    var catId = values[0];
    var otherId = values[1];
});
</pre>
<p>Wasn't that easy</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devexp.eu/2009/01/30/select-element-return-2-values/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
