<?xml version="1.0" encoding="iso-8859-1"?>
<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>Web Words &#187; SQL and Database Things</title>
	<atom:link href="http://wizardev.ca/web-words/category/sql-database/feed/" rel="self" type="application/rss+xml" />
	<link>http://wizardev.ca</link>
	<description>Web development resources</description>
	<lastBuildDate>Fri, 04 Feb 2011 02:30:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>10 Tips for Optimizing MySQL Queries</title>
		<link>http://wizardev.ca/10-tips-for-optimizing-mysql-queries/</link>
		<comments>http://wizardev.ca/10-tips-for-optimizing-mysql-queries/#comments</comments>
		<pubDate>Thu, 12 Apr 2007 12:45:34 +0000</pubDate>
		<dc:creator>Mishka</dc:creator>
				<category><![CDATA[SQL and Database Things]]></category>

		<guid isPermaLink="false">http://wizardev.ca/web-words/10-tips-for-optimizing-mysql-queries</guid>
		<description><![CDATA[Read 10 Tips for Optimizing MySQL Queries (Article dated: April 9, 2007) Read the comment too, How not to optimize a MySQL query]]></description>
			<content:encoded><![CDATA[<p>Read <a href="http://www.whenpenguinsattack.com/2007/04/09/10-tips-for-optimizing-mysql-queries/" rel="external">10 Tips for Optimizing MySQL Queries</a> <small>(Article dated: April 9, 2007)</small></p>
<p>Read the comment too, <a href="http://immike.net/blog/2007/04/09/how-not-to-optimize-a-mysql-query/" rel="external">How not to optimize a MySQL query</a></p>
]]></content:encoded>
			<wfw:commentRss>http://wizardev.ca/10-tips-for-optimizing-mysql-queries/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Debunking GROUP BY myths</title>
		<link>http://wizardev.ca/debunking-group-by-myths/</link>
		<comments>http://wizardev.ca/debunking-group-by-myths/#comments</comments>
		<pubDate>Thu, 16 Aug 2007 12:02:57 +0000</pubDate>
		<dc:creator>Mishka</dc:creator>
				<category><![CDATA[SQL and Database Things]]></category>

		<guid isPermaLink="false">http://wizardev.ca/web-words/debunking-group-by-myths</guid>
		<description><![CDATA[There is a popular myth about the SQL GROUP BY clause. The myth holds that &#8216;standard SQL&#8217; requires columns referenced in the SELECT list of a query to also appear in the GROUP BY clause, unless these columns appear exclusively in an aggregated expression. MySQL is often accused of violating this standard. (Article dated: May [...]]]></description>
			<content:encoded><![CDATA[<p>There is a popular myth about the SQL GROUP BY clause. The myth holds that &#8216;standard SQL&#8217; requires columns referenced in the SELECT list of a query to also appear in the GROUP BY clause, unless these columns appear exclusively in an aggregated expression. MySQL is often accused of violating this standard. <small>(Article dated: May 21, 2007)</small></p>
<p>Read <a href="http://rpbouman.blogspot.com/2007/05/debunking-group-by-myths.html" rel="external">Debunking GROUP BY myths</a></p>
]]></content:encoded>
			<wfw:commentRss>http://wizardev.ca/debunking-group-by-myths/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Finding Duplicate Records and Displaying Each of Them</title>
		<link>http://wizardev.ca/finding-duplicate-records-and-displaying-each-of-them/</link>
		<comments>http://wizardev.ca/finding-duplicate-records-and-displaying-each-of-them/#comments</comments>
		<pubDate>Thu, 21 Jun 2007 12:49:24 +0000</pubDate>
		<dc:creator>Mishka</dc:creator>
				<category><![CDATA[SQL and Database Things]]></category>

		<guid isPermaLink="false">http://wizardev.ca/web-words/finding-duplicate-records-and-displaying-each-of-them</guid>
		<description><![CDATA[Another SQL gem I discovered today. I needed to find records where a first name and last name combination occur more than once, so that the client can verify if they are in fact duplicates, and delete the unnecessary record. SELECT ContactID, LastName, FirstName FROM Contacts WHERE (LastName, FirstName) IN (SELECT LastName, FirstName FROM Contacts [...]]]></description>
			<content:encoded><![CDATA[<p>Another SQL gem I discovered today.  I needed to find records where a first name and last name combination occur more than once, so that the client can verify if they are in fact duplicates, and delete the unnecessary record.</p>
<pre>
SELECT ContactID, LastName, FirstName
   FROM Contacts
   WHERE (LastName, FirstName) IN
   (SELECT LastName, FirstName
       FROM Contacts
       WHERE Active = 1
       GROUP BY LastName, FirstName
       HAVING COUNT(*) > 1)
   ORDER BY LastName, FirstName
</pre>
<p>Source <a href="http://www.devx.com/gethelpon/10MinuteSolution/16597" rel="external">Finding and Eliminating Duplicate Data</a></p>
<p>Along a similar line, but less complicated, I wanted a list of all unique email addresses, along with some additional fields, so <code>SELECT DISTINCT EmailAddress</code> would not suffice.  Here&#8217;s the solution I&#8217;m using:</p>
<pre>
SELECT EmailAddress, ContactID, FirstName, LastName
FROM Contacts
WHERE SubscribeNewsletter = 1
GROUP BY EmailAddress
ORDER BY LastName ASC, FirstName ASC
</pre>
<p>I was a little unsure about the above code, as my references seemed to indicate that GROUP BY needed to work with an aggregate clause, so I reverse-engineered it (read, ran some opposite queries), and am confident the one above is accurate.  </p>
<p>I&#8217;m open to critique.  <img src='http://wizardev.ca/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>UPDATE</strong></p>
<p>It should be noted that the second query above, &#8220;works&#8221; in as much as you get only one row with one name and email address.  You do not get all of the names associated with that particular address.  In my case, this is what I wanted, all email addreses just once, along with a name, any name that uses that address is fine.  </p>
<p>Additionally, this query worked just fine in MySQL, but didn&#8217;t work in PostGresSQL.  Thanks to my great friend <a href="http://rudy.ca/">Rudy</a>, he pointed me in the right direction with the following.</p>
<pre>
SELECT EmailAddress
       , max(ContactID) as max_ContactID
       , max(FirstName) as max_FirstName
       , max(LastName)  as max_LastName
  FROM Contacts
  WHERE SubscribeNewsletter = 1
  GROUP BY EmailAddress
  ORDER BY max_LastName ASC, max_FirstName ASC
</pre>
<p>Some resources for further reading &#8230;</p>
<ul>
<li><a href="http://searchoracle.techtarget.com/expert/KnowledgebaseAnswer/0,289625,sid41_gci1254654,00.html">Employees with the same first and last names in SQL</li>
<li><a href="http://searchoracle.techtarget.com/expert/KnowledgebaseAnswer/0,289625,sid41_gci1263244,00.html">Common SQL questions &#8211; Duplicates</a></li>
<li><a href="http://rpbouman.blogspot.com/2007/05/debunking-group-by-myths.html">Debunking GROUP BY myths</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://wizardev.ca/finding-duplicate-records-and-displaying-each-of-them/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Replace Function</title>
		<link>http://wizardev.ca/mysql-replace-function/</link>
		<comments>http://wizardev.ca/mysql-replace-function/#comments</comments>
		<pubDate>Tue, 17 Apr 2007 23:32:57 +0000</pubDate>
		<dc:creator>Mishka</dc:creator>
				<category><![CDATA[SQL and Database Things]]></category>

		<guid isPermaLink="false">http://wizardev.ca/web-words/mysql-replace-function</guid>
		<description><![CDATA[I&#8217;ve needed this a few times lately&#8230; very handy. update [table_name] set [field_name] = replace([field_name],'[string_to_find]','[string_to_replace]'); Source]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve needed this a few times lately&#8230; very handy.</p>
<p><code>update [table_name] set [field_name] = replace([field_name],'[string_to_find]','[string_to_replace]');</code></p>
<p><a href="http://www.nikmakris.com/2005/mar/29.html" rel="external">Source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://wizardev.ca/mysql-replace-function/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Not so well known data comparison options in MySQL</title>
		<link>http://wizardev.ca/not-so-well-known-data-comparison-options-in-mysql/</link>
		<comments>http://wizardev.ca/not-so-well-known-data-comparison-options-in-mysql/#comments</comments>
		<pubDate>Wed, 14 Feb 2007 12:57:48 +0000</pubDate>
		<dc:creator>Mishka</dc:creator>
				<category><![CDATA[SQL and Database Things]]></category>

		<guid isPermaLink="false">http://wizardev.ca/web-words/not-so-well-known-data-comparison-options-in-mysql</guid>
		<description><![CDATA[It&#8217;s likely that if you&#8217;ve performed a SELECT or UPDATE query in the recent past, you&#8217;ve made use of one or more of MySQL&#8217;s comparison operators in constraining your query&#8217;s output. Comparison is an integral part of most SELECT queries, and MySQL comes with numerous functions for this; at last count, it had over 20 [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s likely that if you&#8217;ve performed a SELECT or UPDATE query in the recent past, you&#8217;ve made use of one or more of MySQL&#8217;s comparison operators in constraining your query&#8217;s output.</p>
<p>Comparison is an integral part of most SELECT queries, and MySQL comes with numerous functions for this; at last count, it had over 20 such operators and functions, ranging from well-known ones like = and LIKE to more esoteric ones like NOT IN and STRCMP(). <small>(Article dated: February 9, 2007)</small></p>
<p>Read: <a href="" rel="external">Get more data comparison options in MySQL with operators you may not know</a></p>
]]></content:encoded>
			<wfw:commentRss>http://wizardev.ca/not-so-well-known-data-comparison-options-in-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Optimizing MySQL: Queries and Indexes</title>
		<link>http://wizardev.ca/optimizing-mysql-queries-and-indexes/</link>
		<comments>http://wizardev.ca/optimizing-mysql-queries-and-indexes/#comments</comments>
		<pubDate>Wed, 08 Nov 2006 15:21:46 +0000</pubDate>
		<dc:creator>Mishka</dc:creator>
				<category><![CDATA[SQL and Database Things]]></category>

		<guid isPermaLink="false">http://wizardev.ca/web-words/optimizing-mysql-queries-and-indexes</guid>
		<description><![CDATA[You know the scene. The database is just too slow. Queries are queuing up, backlogs growing, users being refused connection. Management is ready to spend millions on &#8220;upgrading&#8221; to some other system, when the problem is really that MySQL is simply not being used properly. Read the Article&#8230;]]></description>
			<content:encoded><![CDATA[<p>You know the scene. The database is just too slow. Queries are queuing up, backlogs growing, users being refused connection. Management is ready to spend millions on &#8220;upgrading&#8221; to some other system, when the problem is really that MySQL is simply not being used properly.</p>
<p><a href="http://www.databasejournal.com/features/mysql/article.php/1382791" rel="external">Read the Article&#8230;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://wizardev.ca/optimizing-mysql-queries-and-indexes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Create a New Table with Data from an Existing Table</title>
		<link>http://wizardev.ca/sql-create-a-new-table-with-data-from-an-existing-table/</link>
		<comments>http://wizardev.ca/sql-create-a-new-table-with-data-from-an-existing-table/#comments</comments>
		<pubDate>Tue, 19 Jun 2007 01:20:31 +0000</pubDate>
		<dc:creator>Mishka</dc:creator>
				<category><![CDATA[SQL and Database Things]]></category>

		<guid isPermaLink="false">http://wizardev.ca/web-words/sql-create-a-new-table-with-data-from-an-existing-table</guid>
		<description><![CDATA[Every have one of those situations where you realize, oops, you didn&#8217;t optimize that database schema as well as you should have? (Read, not enough information provided at project start-up.) I needed to copy some information out of my main Contacts table and put it into it&#8217;s own table. Google to the rescue. Read SQL [...]]]></description>
			<content:encoded><![CDATA[<p>Every have one of those situations where you realize, oops, you didn&#8217;t optimize that database schema as well as you should have?  (Read, not enough information provided at project start-up.)  I needed to copy some information out of my main Contacts table and put it into it&#8217;s own table.  Google to the rescue.</p>
<p>Read <a href="http://www.plus2net.com/sql_tutorial/sql_copy_table.php" rel="external">SQL COPY TABLE Command</a></p>
<p>Here&#8217;s what I used, in case I need it again.  <img src='http://wizardev.ca/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  </p>
<pre>
CREATE TABLE VolunteerInfo
SELECT ContactID,
	WhyVolunteer,
	Availability,
	AddNotes,
	VTaskID,
	VolunteerWith,
	OtherTask,
	DateCreated,
	CreatedByID,
	DateModified,
	ModifiedByID
FROM Contacts
WHERE WhyVolunteer <> ''
	or Availability <> ''
	or AddNotes <> ''
	or VTaskID <> ''
	or VolunteerWith <> ''
</pre>
<p>228 records created, add an auto-increment Primary Key for my new table, and humming along to something else.</p>
<p><strong>Note:</strong> To make an existing field an auto-increment Primary Key, you must first make the field a Primary Key, then make it an Auto Increment.  Must be done in two steps. </p>
]]></content:encoded>
			<wfw:commentRss>http://wizardev.ca/sql-create-a-new-table-with-data-from-an-existing-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Understanding Cursors (ASP and ADO)</title>
		<link>http://wizardev.ca/understanding-cursors-asp-and-ado/</link>
		<comments>http://wizardev.ca/understanding-cursors-asp-and-ado/#comments</comments>
		<pubDate>Fri, 01 Jun 2007 11:52:31 +0000</pubDate>
		<dc:creator>Mishka</dc:creator>
				<category><![CDATA[SQL and Database Things]]></category>
		<category><![CDATA[Web Tech]]></category>

		<guid isPermaLink="false">http://wizardev.ca/web-words/understanding-cursors-asp-and-ado</guid>
		<description><![CDATA[Read Understanding Cursors Get the adovbs file]]></description>
			<content:encoded><![CDATA[<p>Read <a href="http://www.adopenstatic.com/faq/jetcursortypes.asp" rel="external">Understanding Cursors</a></p>
<p>Get the <a href="http://www.asp101.com/articles/john/adovbs/adovbs.inc" rel="external">adovbs</a> file</p>
]]></content:encoded>
			<wfw:commentRss>http://wizardev.ca/understanding-cursors-asp-and-ado/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

