<?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>Anthony DeBarros &#187; SQL</title> <atom:link href="http://www.anthonydebarros.com/category/programming/sql/feed/" rel="self" type="application/rss+xml" /><link>http://www.anthonydebarros.com</link> <description>DATA. JOURNALISM. LIFE.</description> <lastBuildDate>Tue, 17 Jan 2012 14:16:00 +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>Calculating Medians With SQL</title><link>http://www.anthonydebarros.com/2010/07/25/calculating-medians-sql/</link> <comments>http://www.anthonydebarros.com/2010/07/25/calculating-medians-sql/#comments</comments> <pubDate>Sun, 25 Jul 2010 04:44:14 +0000</pubDate> <dc:creator>Anthony</dc:creator> <category><![CDATA[Programming]]></category> <category><![CDATA[SQL]]></category><guid isPermaLink="false">http://www.anthonydebarros.com/?p=823</guid> <description><![CDATA[Given that median is such a valuable statistical measure, it&#8217;s baffling that Microsoft&#8217;s SQL Server and other relational databases (MySQL, PostgreSQL) don&#8217;t have a built-in MEDIAN function. Well, this week, after working through a data set in SQL Server &#8212; and deciding I didn&#8217;t want to push the data into SPSS to find medians &#8212; [...]]]></description> <content:encoded><![CDATA[<p><strong>Given that median</strong> is such a <a href="http://www.anthonydebarros.com/2009/12/27/mean-vs-median-excel/" target="_blank">valuable statistical measure</a>, it&#8217;s baffling that Microsoft&#8217;s SQL Server and other relational databases (MySQL, PostgreSQL) don&#8217;t have a built-in MEDIAN function. Well, this week, after working through a data set in SQL Server &#8212; and deciding I didn&#8217;t want to push the data into SPSS to find medians &#8212; I hit the web to find a T-SQL workaround.</p><p>I found a ton of solutions (some from people with no clue about the difference between <a href="http://www.anthonydebarros.com/2009/12/27/mean-vs-median-excel/">median and average</a>), but the one below &#8212; adapted from <a href="http://sqlblog.com/blogs/adam_machanic/archive/2006/12/18/medians-row-numbers-and-performance.aspx" target="_blank">a post by Adam Machanic at sqlblog.com</a> &#8212; was the best. It produces accurate results and is fairly speedy to boot.</p><p>Here&#8217;s an example. Consider this table with student grades from two courses:<br /> <code><span style="color: #ffffff;">.</span></code></p><table border="0"><tbody><tr><th width="30px">ID</th><th width="90px">Class</th><th width="90px">FirstName</th><th>Grade</th></tr><tr><td>1</td><td>Math</td><td>Bob</td><td>65</td></tr><tr><td>2</td><td>Math</td><td>Joe</td><td>72</td></tr><tr><td>3</td><td>Math</td><td>Sally</td><td>95</td></tr><tr><td>4</td><td>Science</td><td>Bob</td><td>65</td></tr><tr><td>5</td><td>Science</td><td>Joe</td><td>81</td></tr><tr><td>6</td><td>Science</td><td>Sally</td><td>81</td></tr><tr><td>7</td><td>Science</td><td>Mike</td><td>72</td></tr></tbody></table><p>We&#8217;d like to find the median grade in each class. Here&#8217;s the script:<br /> <span id="more-823"></span><br /> &nbsp;</p><div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">&nbsp;
<span style="color: #993333; font-weight: bold;">DECLARE</span> @tmp <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #66cc66;">&#40;</span>
   ID <span style="color: #993333; font-weight: bold;">INT</span> <span style="color: #993333; font-weight: bold;">IDENTITY</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
   Class <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
   FirstName <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
   Grade <span style="color: #993333; font-weight: bold;">DECIMAL</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @tmp <span style="color: #66cc66;">&#40;</span>Class<span style="color: #66cc66;">,</span> FirstName<span style="color: #66cc66;">,</span> Grade<span style="color: #66cc66;">&#41;</span>
   <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Math'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Bob'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">65</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @tmp <span style="color: #66cc66;">&#40;</span>Class<span style="color: #66cc66;">,</span> FirstName<span style="color: #66cc66;">,</span> Grade<span style="color: #66cc66;">&#41;</span>
   <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Math'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Joe'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">72</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @tmp <span style="color: #66cc66;">&#40;</span>Class<span style="color: #66cc66;">,</span> FirstName<span style="color: #66cc66;">,</span> Grade<span style="color: #66cc66;">&#41;</span>
   <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Math'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Sally'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">95</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @tmp <span style="color: #66cc66;">&#40;</span>Class<span style="color: #66cc66;">,</span> FirstName<span style="color: #66cc66;">,</span> Grade<span style="color: #66cc66;">&#41;</span>
   <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Science'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Bob'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">65</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @tmp <span style="color: #66cc66;">&#40;</span>Class<span style="color: #66cc66;">,</span> FirstName<span style="color: #66cc66;">,</span> Grade<span style="color: #66cc66;">&#41;</span>
   <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Science'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Joe'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">81</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @tmp <span style="color: #66cc66;">&#40;</span>Class<span style="color: #66cc66;">,</span> FirstName<span style="color: #66cc66;">,</span> Grade<span style="color: #66cc66;">&#41;</span>
   <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Science'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Sally'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">81</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @tmp <span style="color: #66cc66;">&#40;</span>Class<span style="color: #66cc66;">,</span> FirstName<span style="color: #66cc66;">,</span> Grade<span style="color: #66cc66;">&#41;</span>
   <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Science'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Mike'</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">72</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&lt;/</span>code<span style="color: #66cc66;">&gt;</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span>
x<span style="color: #66cc66;">.</span>Class<span style="color: #66cc66;">,</span>
<span style="color: #993333; font-weight: bold;">CAST</span><span style="color: #66cc66;">&#40;</span>AVG<span style="color: #66cc66;">&#40;</span>x<span style="color: #66cc66;">.</span>Grade<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #993333; font-weight: bold;">DECIMAL</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">6</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'Median'</span>
<span style="color: #993333; font-weight: bold;">FROM</span>
   <span style="color: #66cc66;">&#40;</span>
     <span style="color: #993333; font-weight: bold;">SELECT</span>
     Class<span style="color: #66cc66;">,</span>
     FirstName<span style="color: #66cc66;">,</span>
     Grade<span style="color: #66cc66;">,</span>
     <span style="color: #993333; font-weight: bold;">ROW_NUMBER</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">OVER</span> <span style="color: #66cc66;">&#40;</span>
     PARTITION <span style="color: #993333; font-weight: bold;">BY</span> Class
     <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> Grade <span style="color: #993333; font-weight: bold;">ASC</span><span style="color: #66cc66;">,</span> ID <span style="color: #993333; font-weight: bold;">ASC</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> RowAsc<span style="color: #66cc66;">,</span>
     <span style="color: #993333; font-weight: bold;">ROW_NUMBER</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">OVER</span> <span style="color: #66cc66;">&#40;</span>
     PARTITION <span style="color: #993333; font-weight: bold;">BY</span> Class
     <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> Grade <span style="color: #993333; font-weight: bold;">DESC</span><span style="color: #66cc66;">,</span> ID <span style="color: #993333; font-weight: bold;">DESC</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> RowDesc
     <span style="color: #993333; font-weight: bold;">FROM</span> @tmp
   <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> x
<span style="color: #993333; font-weight: bold;">WHERE</span>
RowAsc <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span>RowDesc<span style="color: #66cc66;">,</span> RowDesc <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> RowDesc <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> x<span style="color: #66cc66;">.</span>Class
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> x<span style="color: #66cc66;">.</span>Class</pre></div></div><p>That&#8217;s a lot. Let&#8217;s break down what&#8217;s happening.</p><p>First, to set up the data, we&#8217;re creating a temporary table and inserting seven rows.</p><p>Then comes the main SELECT, which includes a subquery that&#8217;s the meat of the goodness behind this. The subquery uses the <a href="http://msdn.microsoft.com/en-us/library/ms186734.aspx" target="_blank">ROW_NUMBER</a> function to create ascending and descending row identifiers based on the ordering of the grades. It&#8217;s easier to visualize if you see what the subquery&#8217;s creating:<br /> <code><span style="color: #ffffff;">.</span></code></p><table border="0"><tbody><tr><th width="90px">Class</th><th width="90px">FirstName</th><th width="70px">Grade</th><th>RowAsc</th><th>RowDesc</th></tr><tr><td>Math</td><td>Sally</td><td>95.0</td><td>3</td><td>1</td></tr><tr><td>Math</td><td>Joe</td><td>72.0</td><td>2</td><td>2</td></tr><tr><td>Math</td><td>Bob</td><td>65.0</td><td>1</td><td>3</td></tr><tr><td>Science</td><td>Sally</td><td>81.0</td><td>4</td><td>1</td></tr><tr><td>Science</td><td>Joe</td><td>81.0</td><td>3</td><td>2</td></tr><tr><td>Science</td><td>Mike</td><td>72.0</td><td>2</td><td>3</td></tr><tr><td>Science</td><td>Bob</td><td>65.0</td><td>1</td><td>4</td></tr></tbody></table><p>The RowAsc and RowDesc fields reflect the ordered row numbers of the grades per each class (i.e., partition). Given those, it&#8217;s easy to find the median. For the math class, with an odd number of students, the median occurs where RowAsc equals RowDesc. For the science class, with an even number of students, the median is the average of the two grades where RowAsc and RowDesc are within one of each other.</p><p>(Whenever you&#8217;re looking for the median in an ordered list that has an even number of values, averaging the two middle numbers gives the answer.)</p><p>That&#8217;s what our main query does when it pulls from the subquery result set. It looks for:<br /> &nbsp;</p><div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">RowAsc <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">&#40;</span>RowDesc<span style="color: #66cc66;">,</span> RowDesc <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span> RowDesc <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span></pre></div></div><p>and then averages what it finds. The answer is 72 for the math class and 76.5 for science.</p><p>This solution works with T-SQL and Microsoft SQL Server. With minor tweaks, it also runs fine in PostgreSQL 8.4, which also implements the ROW_NUMBER function. MySQL does not support that function, so you&#8217;ll have to search for another option.</p><p>Good stuff and pretty handy for extracting large numbers of median values without having to resort to a stats program.</p> ]]></content:encoded> <wfw:commentRss>http://www.anthonydebarros.com/2010/07/25/calculating-medians-sql/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Essential SQL Queries (To Me, At Least)</title><link>http://www.anthonydebarros.com/2010/03/11/essential-sql-queries/</link> <comments>http://www.anthonydebarros.com/2010/03/11/essential-sql-queries/#comments</comments> <pubDate>Thu, 11 Mar 2010 20:44:05 +0000</pubDate> <dc:creator>Anthony</dc:creator> <category><![CDATA[Programming]]></category> <category><![CDATA[SQL]]></category><guid isPermaLink="false">http://www.anthonydebarros.com/?p=428</guid> <description><![CDATA[For a session of five-minute &#8220;lightning talks&#8221; at this week&#8217;s 2010 Investigative Reporters and Editors conference in Phoenix, I contributed &#8220;Five Essential Queries for SQL Server.&#8221; Aside from the basic SELECT statement, these are five techniques that, at least for me, either solved a tricky problem or made coding life more efficient. They came to [...]]]></description> <content:encoded><![CDATA[<p><strong>For a session of</strong> five-minute <a href="http://en.wikipedia.org/wiki/Lightning_Talk" target="_blank">&#8220;lightning talks&#8221;</a> at this week&#8217;s 2010 Investigative Reporters and Editors conference in Phoenix, I contributed &#8220;Five Essential Queries for SQL Server.&#8221; Aside from the basic SELECT statement, these are five techniques that, at least for me, either solved a tricky problem or made coding life more efficient. They came to me after some trial and error or from using the coder&#8217;s best friend, Google.</p><p>I realize that many journalists prefer the open source (free) MySQL to Microsoft&#8217;s product, so I&#8217;ve replicated the five queries below in MySQL syntax. You can download script files for either syntax here:</p><p>&#8211; <a href="http://www.anthonydebarros.com/wp-content/themes/portfolio_ad/docs/FiveEssentialSQLQueries_SQLServer.sql" target="_blank">Five essential queries (MS SQL Server)</a><br /> &#8211; <a href="http://www.anthonydebarros.com/wp-content/themes/portfolio_ad/docs/FiveEssentialSQLQueries_MySQL.sql" target="_blank">Five essential queries (MySQL)</a></p><p>Feedback and your ideas are welcome. Here they are:</p><p><strong>1. Create a temporary table with identity column.</strong><br /> Temp tables are handy for storing and manipulating data when you need a table but don&#8217;t want to make it part of your actual schema. In SQL Server, the table variable is held in memory and disappears once the query finishes executing.<br /> &nbsp;</p><div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">DECLARE</span> @tmp <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #66cc66;">&#40;</span>
   id <span style="color: #993333; font-weight: bold;">INT</span> <span style="color: #993333; font-weight: bold;">IDENTITY</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> 
   FirstName <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @tmp <span style="color: #66cc66;">&#40;</span>FirstName<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Bob'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @tmp <span style="color: #66cc66;">&#40;</span>FirstName<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Joe'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @tmp <span style="color: #66cc66;">&#40;</span>FirstName<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Sally'</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> @tmp</pre></div></div><p><span id="more-428"></span><br /> <strong>2. Use a CASE expression to update a field based on values in another field.</strong><br /> Here, we create a temporary table that has FirstName and NickName fields. If we want to update the NickName field based on the values found in FirstName, we can use a standard UPDATE statement with CASE embedded.<br /> &nbsp;</p><div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">DECLARE</span> @tmp <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #66cc66;">&#40;</span>
   id <span style="color: #993333; font-weight: bold;">INT</span> <span style="color: #993333; font-weight: bold;">IDENTITY</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
   FirstName <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
   NickName <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @tmp <span style="color: #66cc66;">&#40;</span>FirstName<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Robert'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @tmp <span style="color: #66cc66;">&#40;</span>FirstName<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Joseph'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @tmp <span style="color: #66cc66;">&#40;</span>FirstName<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Elizabeth'</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">UPDATE</span> @tmp
<span style="color: #993333; font-weight: bold;">SET</span> Nickname <span style="color: #66cc66;">=</span>
   <span style="color: #993333; font-weight: bold;">CASE</span>
      <span style="color: #993333; font-weight: bold;">WHEN</span> FirstName <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Robert'</span> <span style="color: #993333; font-weight: bold;">THEN</span> <span style="color: #ff0000;">'Bob'</span> 
      <span style="color: #993333; font-weight: bold;">WHEN</span> FirstName <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Joseph'</span> <span style="color: #993333; font-weight: bold;">THEN</span> <span style="color: #ff0000;">'Joe'</span> 
      <span style="color: #993333; font-weight: bold;">WHEN</span> FirstName <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Elizabeth'</span> <span style="color: #993333; font-weight: bold;">THEN</span> <span style="color: #ff0000;">'Liz'</span> 
   <span style="color: #993333; font-weight: bold;">END</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> @tmp</pre></div></div><p><strong>3. Join a table to itself using aliasing.</strong><br /> Sometimes, it&#8217;s handy to be able to join a table to itself or to join the results of two or more queries. Using aliases is a helpful way to do this. In this example, we create a table to hold information on eating contests. Each row has the result for one contestant and includes name, contest date and their result.</p><p>Let&#8217;s say we want to know, for each contestant, their most recent contest and how well they did. First we need to find the maximum date for their name and then find the result on that date. We do both operations as separate queries and assign each an alias &#8212; in this case, A and B. We can then join those to query them as if they were two separate tables.<br /> &nbsp;</p><div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">DECLARE</span> @EatingContests <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #66cc66;">&#40;</span>
   id <span style="color: #993333; font-weight: bold;">INT</span> <span style="color: #993333; font-weight: bold;">IDENTITY</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
   FirstName <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
   cDate datetime<span style="color: #66cc66;">,</span>
   Result <span style="color: #993333; font-weight: bold;">INT</span>
   <span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @EatingContests <span style="color: #66cc66;">&#40;</span>FirstName<span style="color: #66cc66;">,</span> cDate<span style="color: #66cc66;">,</span> Result<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Bill'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'3/2/2010'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'4'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @EatingContests <span style="color: #66cc66;">&#40;</span>FirstName<span style="color: #66cc66;">,</span> cDate<span style="color: #66cc66;">,</span> Result<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Bill'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'5/18/2010'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'3'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @EatingContests <span style="color: #66cc66;">&#40;</span>FirstName<span style="color: #66cc66;">,</span> cDate<span style="color: #66cc66;">,</span> Result<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Bill'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'12/19/2010'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'1'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @EatingContests <span style="color: #66cc66;">&#40;</span>FirstName<span style="color: #66cc66;">,</span> cDate<span style="color: #66cc66;">,</span> Result<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Lisa'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'3/2/2010'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'6'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @EatingContests <span style="color: #66cc66;">&#40;</span>FirstName<span style="color: #66cc66;">,</span> cDate<span style="color: #66cc66;">,</span> Result<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Lisa'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'12/7/2009'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'1'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @EatingContests <span style="color: #66cc66;">&#40;</span>FirstName<span style="color: #66cc66;">,</span> cDate<span style="color: #66cc66;">,</span> Result<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Lisa'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'1/6/2010'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'2'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @EatingContests <span style="color: #66cc66;">&#40;</span>FirstName<span style="color: #66cc66;">,</span> cDate<span style="color: #66cc66;">,</span> Result<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Lou'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'3/2/2010'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'3'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @EatingContests <span style="color: #66cc66;">&#40;</span>FirstName<span style="color: #66cc66;">,</span> cDate<span style="color: #66cc66;">,</span> Result<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Lou'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'4/4/2010'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'5'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @EatingContests <span style="color: #66cc66;">&#40;</span>FirstName<span style="color: #66cc66;">,</span> cDate<span style="color: #66cc66;">,</span> Result<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Lou'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'9/16/2009'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'1'</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> A<span style="color: #66cc66;">.</span>FirstName<span style="color: #66cc66;">,</span> A<span style="color: #66cc66;">.</span>MaxDate<span style="color: #66cc66;">,</span> B<span style="color: #66cc66;">.</span>Result
<span style="color: #993333; font-weight: bold;">FROM</span>
   <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> FirstName<span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">MAX</span><span style="color: #66cc66;">&#40;</span>cDate<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'MaxDate'</span>
   <span style="color: #993333; font-weight: bold;">FROM</span> @EatingContests
   <span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> FirstName<span style="color: #66cc66;">&#41;</span>
   <span style="color: #993333; font-weight: bold;">AS</span> A
<span style="color: #993333; font-weight: bold;">LEFT</span> <span style="color: #993333; font-weight: bold;">JOIN</span>
   <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">SELECT</span> FirstName<span style="color: #66cc66;">,</span> cDate<span style="color: #66cc66;">,</span> Result
   <span style="color: #993333; font-weight: bold;">FROM</span> @EatingContests<span style="color: #66cc66;">&#41;</span>
   <span style="color: #993333; font-weight: bold;">AS</span> B
<span style="color: #993333; font-weight: bold;">ON</span> A<span style="color: #66cc66;">.</span>FirstName <span style="color: #66cc66;">=</span> B<span style="color: #66cc66;">.</span>FirstName <span style="color: #993333; font-weight: bold;">AND</span> A<span style="color: #66cc66;">.</span>MaxDate <span style="color: #66cc66;">=</span> B<span style="color: #66cc66;">.</span>cDate</pre></div></div><p><strong>4. Rank query results.</strong><br /> SQL Server has a very handy RANK function that will return the rank of a value we specify in the query.</p><p>Here we have a table of names and salaries. We use RANK to order the names by salary and provide the rank. Note that RANK shows that two people tied for 2nd and then ranks the next person 4th.<br /> &nbsp;</p><div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">DECLARE</span> @tmp <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #66cc66;">&#40;</span>
   id <span style="color: #993333; font-weight: bold;">INT</span> <span style="color: #993333; font-weight: bold;">IDENTITY</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
   FirstName <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
   Salary <span style="color: #993333; font-weight: bold;">INT</span>
   <span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @tmp <span style="color: #66cc66;">&#40;</span>FirstName<span style="color: #66cc66;">,</span> Salary<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Robert'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'25000'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @tmp <span style="color: #66cc66;">&#40;</span>FirstName<span style="color: #66cc66;">,</span> Salary<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Jan'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'36000'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @tmp <span style="color: #66cc66;">&#40;</span>FirstName<span style="color: #66cc66;">,</span> Salary<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Mike'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'48000'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @tmp <span style="color: #66cc66;">&#40;</span>FirstName<span style="color: #66cc66;">,</span> Salary<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Sarah'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'51000'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @tmp <span style="color: #66cc66;">&#40;</span>FirstName<span style="color: #66cc66;">,</span> Salary<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Lisa'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'48000'</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> @tmp <span style="color: #66cc66;">&#40;</span>FirstName<span style="color: #66cc66;">,</span> Salary<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Steve'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'22000'</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span> FirstName<span style="color: #66cc66;">,</span> Salary<span style="color: #66cc66;">,</span> RANK<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">OVER</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> Salary <span style="color: #993333; font-weight: bold;">DESC</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">'Rank'</span>
<span style="color: #993333; font-weight: bold;">FROM</span> @tmp</pre></div></div><p><strong>5. Concatenate row values into one field</strong><br /> The table created with the script below has names and test scores. For some applications, it&#8217;s handy to present these values in a list, such as &#8220;82, 93, 74&#8243;.</p><p>MySQL&#8217;s GROUP_CONCAT function does this easily, but there&#8217;s no similar option in SQL Server. It can be done, though, and this syntax (which I stumbled upon after an eternity of Googling), makes use of both the STUFF function and the FOR XML PATH output option. STUFF inserts text inside another piece of text.<br /> &nbsp;</p><div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> #tmp <span style="color: #66cc66;">&#40;</span>
   id <span style="color: #993333; font-weight: bold;">INT</span> <span style="color: #993333; font-weight: bold;">IDENTITY</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
   FirstName <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
   Score <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> #tmp <span style="color: #66cc66;">&#40;</span>FirstName<span style="color: #66cc66;">,</span> Score<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Dana'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'82'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> #tmp <span style="color: #66cc66;">&#40;</span>FirstName<span style="color: #66cc66;">,</span> Score<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Dana'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'93'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> #tmp <span style="color: #66cc66;">&#40;</span>FirstName<span style="color: #66cc66;">,</span> Score<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Dana'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'74'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> #tmp <span style="color: #66cc66;">&#40;</span>FirstName<span style="color: #66cc66;">,</span> Score<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Tammy'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'92'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> #tmp <span style="color: #66cc66;">&#40;</span>FirstName<span style="color: #66cc66;">,</span> Score<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Tammy'</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'98'</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333; font-weight: bold;">SELECT</span>
FirstName<span style="color: #66cc66;">,</span>
   STUFF<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>
      <span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">', '</span> <span style="color: #66cc66;">+</span> t<span style="color: #66cc66;">.</span>Score
      <span style="color: #993333; font-weight: bold;">FROM</span> #tmp t
      <span style="color: #993333; font-weight: bold;">WHERE</span> t<span style="color: #66cc66;">.</span>FirstName <span style="color: #66cc66;">=</span> #tmp<span style="color: #66cc66;">.</span>FirstName
      <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> t<span style="color: #66cc66;">.</span>Score <span style="color: #993333; font-weight: bold;">DESC</span>
      <span style="color: #993333; font-weight: bold;">FOR</span> XML PATH<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span>
   <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> Scores
<span style="color: #993333; font-weight: bold;">FROM</span> #tmp
<span style="color: #993333; font-weight: bold;">GROUP</span> <span style="color: #993333; font-weight: bold;">BY</span> FirstName
&nbsp;
<span style="color: #993333; font-weight: bold;">DROP</span> <span style="color: #993333; font-weight: bold;">TABLE</span> #tmp</pre></div></div><p>Hope you find those useful. Feel free to share your favorites.</p> ]]></content:encoded> <wfw:commentRss>http://www.anthonydebarros.com/2010/03/11/essential-sql-queries/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 1/11 queries in 0.008 seconds using disk: basic
Object Caching 261/272 objects using disk: basic

Served from: www.anthonydebarros.com @ 2012-02-05 06:12:14 -->
