<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Getting the first 5 records of type X in MySQL</title>
	<atom:link href="http://www.adaniels.nl/articles/getting-the-first-5-records-of-type-x-in-mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.adaniels.nl/articles/getting-the-first-5-records-of-type-x-in-mysql/</link>
	<description>It's all about me, mysql and Einstein.</description>
	<lastBuildDate>Fri, 19 Mar 2010 15:00:30 +0100</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: gigiduru</title>
		<link>http://www.adaniels.nl/articles/getting-the-first-5-records-of-type-x-in-mysql/comment-page-1/#comment-5974</link>
		<dc:creator>gigiduru</dc:creator>
		<pubDate>Mon, 12 Nov 2007 20:46:05 +0000</pubDate>
		<guid isPermaLink="false">http://blog.adaniels.nl/?p=60#comment-5974</guid>
		<description>Sorry for stepping on your toes but I really hate when someone disregard my comments for &quot;unknown&quot; reasons or just because he/she feels so. It&#039;s rude. Now that we cleared out why it happened, I guess there&#039;s no reason to beat the drum on it anymore.

Paranoid - yeah, maybe, I&#039;ll take it as a compliment. Especially when mysql crashes doing inserts on a 400 GB database using myisam tables... Not my storage engine of choice either.

Also, keep in mind, I started down on mysql road with all the enthusiasm, which also happened to lose it bit by bit dealing with its crapness on daily basis.</description>
		<content:encoded><![CDATA[<p>Sorry for stepping on your toes but I really hate when someone disregard my comments for &#8220;unknown&#8221; reasons or just because he/she feels so. It&#8217;s rude. Now that we cleared out why it happened, I guess there&#8217;s no reason to beat the drum on it anymore.</p>
<p>Paranoid &#8211; yeah, maybe, I&#8217;ll take it as a compliment. Especially when mysql crashes doing inserts on a 400 GB database using myisam tables&#8230; Not my storage engine of choice either.</p>
<p>Also, keep in mind, I started down on mysql road with all the enthusiasm, which also happened to lose it bit by bit dealing with its crapness on daily basis.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arnold Daniels</title>
		<link>http://www.adaniels.nl/articles/getting-the-first-5-records-of-type-x-in-mysql/comment-page-1/#comment-5813</link>
		<dc:creator>Arnold Daniels</dc:creator>
		<pubDate>Sat, 10 Nov 2007 11:47:49 +0000</pubDate>
		<guid isPermaLink="false">http://blog.adaniels.nl/?p=60#comment-5813</guid>
		<description>Nice and paranoid are we gigiduru. I have to approve comments manually and at 00:43 I&#039;m either sleeping or drinking beer.

I understand the frustration when you have the superior product, but can&#039;t get people to switch. We supper the same with &lt;a href=&quot;http://javeline.com&quot; rel=&quot;nofollow&quot;&gt;Javeline PlatForm&lt;/a&gt;.</description>
		<content:encoded><![CDATA[<p>Nice and paranoid are we gigiduru. I have to approve comments manually and at 00:43 I&#8217;m either sleeping or drinking beer.</p>
<p>I understand the frustration when you have the superior product, but can&#8217;t get people to switch. We supper the same with <a href="http://javeline.com" rel="nofollow">Javeline PlatForm</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gigiduru</title>
		<link>http://www.adaniels.nl/articles/getting-the-first-5-records-of-type-x-in-mysql/comment-page-1/#comment-5787</link>
		<dc:creator>gigiduru</dc:creator>
		<pubDate>Sat, 10 Nov 2007 02:44:41 +0000</pubDate>
		<guid isPermaLink="false">http://blog.adaniels.nl/?p=60#comment-5787</guid>
		<description>Thank your for removing my comment.

That remembers me about the censorship.</description>
		<content:encoded><![CDATA[<p>Thank your for removing my comment.</p>
<p>That remembers me about the censorship.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gigiduru</title>
		<link>http://www.adaniels.nl/articles/getting-the-first-5-records-of-type-x-in-mysql/comment-page-1/#comment-5782</link>
		<dc:creator>gigiduru</dc:creator>
		<pubDate>Fri, 09 Nov 2007 23:43:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.adaniels.nl/?p=60#comment-5782</guid>
		<description>The most elegant solution is use top-n queries.

Oh wait, I forgot, this piece of crap dbms doesn&#039;t know about top-n queries, among other things missing like data integrity features, minus operation, real trigger support (without memory leaks), stored procedures that are using the query cache....etc.

On short, the solution is to use PostgreSQL.</description>
		<content:encoded><![CDATA[<p>The most elegant solution is use top-n queries.</p>
<p>Oh wait, I forgot, this piece of crap dbms doesn&#8217;t know about top-n queries, among other things missing like data integrity features, minus operation, real trigger support (without memory leaks), stored procedures that are using the query cache&#8230;.etc.</p>
<p>On short, the solution is to use PostgreSQL.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David H</title>
		<link>http://www.adaniels.nl/articles/getting-the-first-5-records-of-type-x-in-mysql/comment-page-1/#comment-5778</link>
		<dc:creator>David H</dc:creator>
		<pubDate>Fri, 09 Nov 2007 21:51:03 +0000</pubDate>
		<guid isPermaLink="false">http://blog.adaniels.nl/?p=60#comment-5778</guid>
		<description>Nice! You probably already know this -- on your subquery, add &#039;, Country&#039; after the order by statement if you wish to have the countries in alphanumerical order... 

SELECT @a:=IF(@b=Continent, @a+1, 0) AS a, Name, @b:=Continent AS Continent FROM Country ORDER BY Continent, Country

If the query does not scale well on a large database and you can control the output (limiting the number of countries), try this:
SELECT Name, GROUP_CONCAT(DISTINCT Name order by Name ASC SEPARATOR &#039;, &#039;) AS Countries FROM Country GROUP BY continent;

Note that it cannot limit the number of countries per line.  Perhaps this can be a feature in a future version of mySql? :)

-David</description>
		<content:encoded><![CDATA[<p>Nice! You probably already know this &#8212; on your subquery, add &#8216;, Country&#8217; after the order by statement if you wish to have the countries in alphanumerical order&#8230; </p>
<p>SELECT @a:=IF(@b=Continent, @a+1, 0) AS a, Name, @b:=Continent AS Continent FROM Country ORDER BY Continent, Country</p>
<p>If the query does not scale well on a large database and you can control the output (limiting the number of countries), try this:<br />
SELECT Name, GROUP_CONCAT(DISTINCT Name order by Name ASC SEPARATOR &#8216;, &#8216;) AS Countries FROM Country GROUP BY continent;</p>
<p>Note that it cannot limit the number of countries per line.  Perhaps this can be a feature in a future version of mySql? <img src='http://www.adaniels.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>-David</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rudy</title>
		<link>http://www.adaniels.nl/articles/getting-the-first-5-records-of-type-x-in-mysql/comment-page-1/#comment-5772</link>
		<dc:creator>rudy</dc:creator>
		<pubDate>Fri, 09 Nov 2007 20:02:13 +0000</pubDate>
		<guid isPermaLink="false">http://blog.adaniels.nl/?p=60#comment-5772</guid>
		<description>define &quot;first 5&quot;

your solution looks like it&#039;s actually &quot;any 5&quot;

there are several ways to do it, depending on what you really mean</description>
		<content:encoded><![CDATA[<p>define &#8220;first 5&#8243;</p>
<p>your solution looks like it&#8217;s actually &#8220;any 5&#8243;</p>
<p>there are several ways to do it, depending on what you really mean</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://www.adaniels.nl/articles/getting-the-first-5-records-of-type-x-in-mysql/comment-page-1/#comment-5767</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Fri, 09 Nov 2007 17:31:52 +0000</pubDate>
		<guid isPermaLink="false">http://blog.adaniels.nl/?p=60#comment-5767</guid>
		<description>I&#039;m don&#039;t have access to a MySQL database so can&#039;t try this, but how about using a LIMIT 5 clause?</description>
		<content:encoded><![CDATA[<p>I&#8217;m don&#8217;t have access to a MySQL database so can&#8217;t try this, but how about using a LIMIT 5 clause?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arnold Daniels</title>
		<link>http://www.adaniels.nl/articles/getting-the-first-5-records-of-type-x-in-mysql/comment-page-1/#comment-5763</link>
		<dc:creator>Arnold Daniels</dc:creator>
		<pubDate>Fri, 09 Nov 2007 16:49:27 +0000</pubDate>
		<guid isPermaLink="false">http://blog.adaniels.nl/?p=60#comment-5763</guid>
		<description>Marc: Yes I&#039;ve read your solutions some time ago. Though nice, that only works (well) for a single record per type.

Bill: That looks like a nice solution. You do get a huge resultset which has to be filtered with a HAVING, so I&#039;m not sure if it scales better.

Jeff: I don&#039;t know how it scales. I might run some benchmarks this weekend (if I manage to stay away from hangovers). If you want to benchmark it, please do.</description>
		<content:encoded><![CDATA[<p>Marc: Yes I&#8217;ve read your solutions some time ago. Though nice, that only works (well) for a single record per type.</p>
<p>Bill: That looks like a nice solution. You do get a huge resultset which has to be filtered with a HAVING, so I&#8217;m not sure if it scales better.</p>
<p>Jeff: I don&#8217;t know how it scales. I might run some benchmarks this weekend (if I manage to stay away from hangovers). If you want to benchmark it, please do.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yaroslav Vorzohko</title>
		<link>http://www.adaniels.nl/articles/getting-the-first-5-records-of-type-x-in-mysql/comment-page-1/#comment-5762</link>
		<dc:creator>Yaroslav Vorzohko</dc:creator>
		<pubDate>Fri, 09 Nov 2007 16:37:54 +0000</pubDate>
		<guid isPermaLink="false">http://blog.adaniels.nl/?p=60#comment-5762</guid>
		<description>Hi Arnold Daniels.
It&#039;s very cool solution, thanks for share!</description>
		<content:encoded><![CDATA[<p>Hi Arnold Daniels.<br />
It&#8217;s very cool solution, thanks for share!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bill Karwin</title>
		<link>http://www.adaniels.nl/articles/getting-the-first-5-records-of-type-x-in-mysql/comment-page-1/#comment-5761</link>
		<dc:creator>Bill Karwin</dc:creator>
		<pubDate>Fri, 09 Nov 2007 16:25:15 +0000</pubDate>
		<guid isPermaLink="false">http://blog.adaniels.nl/?p=60#comment-5761</guid>
		<description>Here&#039;s an example query to return the top three cities per state by population.  I presented this at OSCON 2006 in a talk &quot;SQL Outer Joins for Fun and Profit&quot;.

SELECT c.state, c.city_name, c.population
FROM cities AS c 
 LEFT JOIN cities AS c2 ON c.state = c2.state
  AND c.population &lt;= c2.population
GROUP BY c.state, c.city_name, c.population
HAVING COUNT(*) &lt;= 3
ORDER BY c.state, c.population DESC;</description>
		<content:encoded><![CDATA[<p>Here&#8217;s an example query to return the top three cities per state by population.  I presented this at OSCON 2006 in a talk &#8220;SQL Outer Joins for Fun and Profit&#8221;.</p>
<p>SELECT c.state, c.city_name, c.population<br />
FROM cities AS c<br />
 LEFT JOIN cities AS c2 ON c.state = c2.state<br />
  AND c.population &lt;= c2.population<br />
GROUP BY c.state, c.city_name, c.population<br />
HAVING COUNT(*) &lt;= 3<br />
ORDER BY c.state, c.population DESC;</p>
]]></content:encoded>
	</item>
</channel>
</rss>
