<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: How to select the Nth greatest/least/first/last row in SQL</title>
	<atom:link href="http://www.xaprb.com/blog/2008/08/08/how-to-select-the-nth-greatestleastfirstlast-row-in-sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.xaprb.com/blog/2008/08/08/how-to-select-the-nth-greatestleastfirstlast-row-in-sql/</link>
	<description>Stay curious!</description>
	<pubDate>Tue, 06 Jan 2009 03:11:13 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: Xaprb</title>
		<link>http://www.xaprb.com/blog/2008/08/08/how-to-select-the-nth-greatestleastfirstlast-row-in-sql/#comment-14996</link>
		<dc:creator>Xaprb</dc:creator>
		<pubDate>Wed, 13 Aug 2008 00:36:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.xaprb.com/blog/2008/08/08/how-to-select-the-nth-greatestleastfirstlast-row-in-sql/#comment-14996</guid>
		<description>Nope, because the first query finds the two cheapest prices for each fruit, so that would effectively be "find the min of the min" which is... the min, or the 1st cheapest.

Try it and see!</description>
		<content:encoded><![CDATA[<p>Nope, because the first query finds the two cheapest prices for each fruit, so that would effectively be &#8220;find the min of the min&#8221; which is&#8230; the min, or the 1st cheapest.</p>
<p>Try it and see!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rijk van Wel</title>
		<link>http://www.xaprb.com/blog/2008/08/08/how-to-select-the-nth-greatestleastfirstlast-row-in-sql/#comment-14995</link>
		<dc:creator>Rijk van Wel</dc:creator>
		<pubDate>Tue, 12 Aug 2008 20:03:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.xaprb.com/blog/2008/08/08/how-to-select-the-nth-greatestleastfirstlast-row-in-sql/#comment-14995</guid>
		<description>Nice article, but isn't the 2nd cheapest the _least_ expensive of the fruits found in the first query (so "min(price) as second_cheapest")?</description>
		<content:encoded><![CDATA[<p>Nice article, but isn&#8217;t the 2nd cheapest the _least_ expensive of the fruits found in the first query (so &#8220;min(price) as second_cheapest&#8221;)?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jordi Baylina</title>
		<link>http://www.xaprb.com/blog/2008/08/08/how-to-select-the-nth-greatestleastfirstlast-row-in-sql/#comment-14985</link>
		<dc:creator>Jordi Baylina</dc:creator>
		<pubDate>Mon, 11 Aug 2008 07:57:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.xaprb.com/blog/2008/08/08/how-to-select-the-nth-greatestleastfirstlast-row-in-sql/#comment-14985</guid>
		<description>A simplification:


select sum(price)
from fruits f1
where
( select count(*)
from fruits f2
where f1.type=f2.type and
f2.price &#60;= f1.price
) = 2


If can exists multiple varieties with the same price then:


select sum(price) from fruits f1
where (
select count(*)
from fruits f2
where f1.type=f2.type and
      ((f2.price &#60; f1.price) or ( (f2.price=f1.price) and
                                    (f2.variety &#60; f1.variety)))

)  =1
</description>
		<content:encoded><![CDATA[<p>A simplification:</p>
<p>select sum(price)<br />
from fruits f1<br />
where<br />
( select count(*)<br />
from fruits f2<br />
where f1.type=f2.type and<br />
f2.price &lt;= f1.price<br />
) = 2</p>
<p>If can exists multiple varieties with the same price then:</p>
<p>select sum(price) from fruits f1<br />
where (<br />
select count(*)<br />
from fruits f2<br />
where f1.type=f2.type and<br />
      ((f2.price &lt; f1.price) or ( (f2.price=f1.price) and<br />
                                    (f2.variety &lt; f1.variety)))</p>
<p>)  =1</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gints</title>
		<link>http://www.xaprb.com/blog/2008/08/08/how-to-select-the-nth-greatestleastfirstlast-row-in-sql/#comment-14977</link>
		<dc:creator>Gints</dc:creator>
		<pubDate>Sat, 09 Aug 2008 21:21:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.xaprb.com/blog/2008/08/08/how-to-select-the-nth-greatestleastfirstlast-row-in-sql/#comment-14977</guid>
		<description>As soon as MySQL will add analytic functions, it will be muuuuch easier :)</description>
		<content:encoded><![CDATA[<p>As soon as MySQL will add analytic functions, it will be muuuuch easier :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Xaprb</title>
		<link>http://www.xaprb.com/blog/2008/08/08/how-to-select-the-nth-greatestleastfirstlast-row-in-sql/#comment-14972</link>
		<dc:creator>Xaprb</dc:creator>
		<pubDate>Sat, 09 Aug 2008 02:00:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.xaprb.com/blog/2008/08/08/how-to-select-the-nth-greatestleastfirstlast-row-in-sql/#comment-14972</guid>
		<description>Approach it the other direction.

First, get the data on the last post in each thread.  See my earlier posts for this.

Then join to the threads.</description>
		<content:encoded><![CDATA[<p>Approach it the other direction.</p>
<p>First, get the data on the last post in each thread.  See my earlier posts for this.</p>
<p>Then join to the threads.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
