<?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>Under Development :: Life in the Virtual World &#187; MySQL</title>
	<atom:link href="http://underdevelopment.maravillaclan.net/category/php-mysql/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://underdevelopment.maravillaclan.net</link>
	<description>Learning to do it a little better</description>
	<lastBuildDate>Wed, 09 Dec 2009 12:23:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Inserting records from a SELECT statement (MySQL)</title>
		<link>http://underdevelopment.maravillaclan.net/2008/09/09/inserting-records-from-a-select-statement-mysql/</link>
		<comments>http://underdevelopment.maravillaclan.net/2008/09/09/inserting-records-from-a-select-statement-mysql/#comments</comments>
		<pubDate>Tue, 09 Sep 2008 06:32:20 +0000</pubDate>
		<dc:creator>Bong-Bong</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://underdevelopment.maravillaclan.net/?p=68</guid>
		<description><![CDATA[I often forget even simple syntax that makes MySQL operation easy. I&#8217;m just adding this basically for personal reference.
Using INSERT statement combined with the SELECT statement you could actually add records from one table to another table. Adding a WHERE clause could enable you to filter the records to copy. Below is the syntax.

INSERT INTO [...]]]></description>
			<content:encoded><![CDATA[<p>I often forget even simple syntax that makes MySQL operation easy. I&#8217;m just adding this basically for personal reference.</p>
<p>Using INSERT statement combined with the SELECT statement you could actually add records from one table to another table. Adding a WHERE clause could enable you to filter the records to copy. Below is the syntax.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> table_destination <span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> table_source <span style="color: #66cc66;">&#91;</span><span style="color: #993333; font-weight: bold;">WHERE</span> condition<span style="color: #66cc66;">&#93;</span>;</pre></div></div>

<p>However this generic statement only works if the two tables have the same order of columns and has compatible data types. If that is not the case you would need to specify the columns like the following syntax:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> table_destination <span style="color: #66cc66;">&#40;</span>column_1<span style="color: #66cc66;">,</span> column_2<span style="color: #66cc66;">,</span> column_3<span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">SELECT</span> column_1<span style="color: #66cc66;">,</span> column_2<span style="color: #66cc66;">,</span> column_3 <span style="color: #993333; font-weight: bold;">FROM</span> table_source <span style="color: #66cc66;">&#91;</span><span style="color: #993333; font-weight: bold;">WHERE</span> condition<span style="color: #66cc66;">&#93;</span>;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://underdevelopment.maravillaclan.net/2008/09/09/inserting-records-from-a-select-statement-mysql/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>NOT id IN (1, 2, 3) vs NOT (id IN (1, 2, 3))</title>
		<link>http://underdevelopment.maravillaclan.net/2008/09/05/not-id-in-1-2-3-vs-not-id-in-1-2-3/</link>
		<comments>http://underdevelopment.maravillaclan.net/2008/09/05/not-id-in-1-2-3-vs-not-id-in-1-2-3/#comments</comments>
		<pubDate>Fri, 05 Sep 2008 05:23:00 +0000</pubDate>
		<dc:creator>Bong-Bong</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://underdevelopment.maravillaclan.net/?p=59</guid>
		<description><![CDATA[Problem:
You&#8217;re probably wondering why the following query doesn&#8217;t  work on some mySQL databases
SELECT * FROM table1 WHERE NOT id IN (1, 2, 3)
works on mySQL v5.0.51a
doesn&#8217;t work on mySQL v4.1.21
Solution:
The reason is that the query would confuse the older version what to evaluate by NOT.
This query generally works.
SELECT * FROM table1 WHERE NOT (id IN [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong></p>
<p>You&#8217;re probably wondering why the following query doesn&#8217;t  work on some mySQL databases</p>
<p><span style="color: #0000ff;">SELECT</span> * <span style="color: #0000ff;">FROM</span> <span style="color: #00ff00;">table1 </span><span style="color: #0000ff;">WHERE NOT</span> <span style="color: #00ff00;">id </span><span style="color: #0000ff;">IN</span> (<span style="color: #ff0000;">1</span>, <span style="color: #ff0000;">2</span>, <span style="color: #ff0000;">3</span>)<br />
works on mySQL v5.0.51a<br />
doesn&#8217;t work on mySQL v4.1.21</p>
<p><strong>Solution:</strong><span id="more-59"></span></p>
<p>The reason is that the query would confuse the older version what to evaluate by NOT.</p>
<p>This query generally works.</p>
<p><span style="color: #0000ff;">SELECT</span> * <span style="color: #0000ff;">FROM</span> <span style="color: #00ff00;">table1 </span><span style="color: #0000ff;">WHERE NOT</span> (<span style="color: #00ff00;">id </span><span style="color: #0000ff;">IN</span> (<span style="color: #ff0000;">1</span>, <span style="color: #ff0000;">2</span>, <span style="color: #ff0000;">3</span>))<br />
works on mySQL v5.0.51a<br />
works on mySQL v4.1.21</p>
<p>This is basically just specifying what should value should be evaluated by NOT.</p>
]]></content:encoded>
			<wfw:commentRss>http://underdevelopment.maravillaclan.net/2008/09/05/not-id-in-1-2-3-vs-not-id-in-1-2-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
