<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel> 

	<title>Comments on: select "order by occurrence" mysql</title>
	<link>http://ask.metafilter.com/21842/select-order-by-occurrence-mysql/</link>
	<description>Comments on Ask MetaFilter post select "order by occurrence" mysql</description>
	<pubDate>Thu, 28 Jul 2005 14:40:12 -0800</pubDate>
	<lastBuildDate>Thu, 28 Jul 2005 14:40:12 -0800</lastBuildDate>
	<language>en-us</language>
	<docs>http://blogs.law.harvard.edu/tech/rss</docs>
	<ttl>60</ttl>

	<item>
		<title>Question: select &quot;order by occurrence&quot; mysql</title>
		<link>http://ask.metafilter.com/21842/select-order-by-occurrence-mysql</link>	
		<description>Does any one know how to find the most common result for a column returned from a mysql select request? </description>
		<guid isPermaLink="false">post:ask.metafilter.com,2005:site.21842</guid>
		<pubDate>Thu, 28 Jul 2005 14:35:20 -0800</pubDate>
		<dc:creator>outofpaper</dc:creator>
		
			<category>php</category>
		
			<category>mysql</category>
		
			<category>programing</category>
		
	</item> <item>
		<title>By: wackybrit</title>
		<link>http://ask.metafilter.com/21842/select-order-by-occurrence-mysql#351737</link>	
		<description>Untested, but something like.. &lt;br&gt;
&lt;br&gt;
SELECT *, COUNT(desiredcolumn) AS occurances FROM table GROUP BY occurances ORDER BY occurances DESC LIMIT 1;&lt;br&gt;
&lt;br&gt;
should work (may need a bit of fixing).</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2005:site.21842-351737</guid>
		<pubDate>Thu, 28 Jul 2005 14:40:12 -0800</pubDate>
		<dc:creator>wackybrit</dc:creator>
	</item><item>
		<title>By: wackybrit</title>
		<link>http://ask.metafilter.com/21842/select-order-by-occurrence-mysql#351739</link>	
		<description>Correction already:&lt;br&gt;
&lt;br&gt;
SELECT *, COUNT(desiredcolumn) AS occurances FROM table GROUP BY &lt;b&gt;&lt;em&gt;desiredcolumn&lt;/em&gt;&lt;/b&gt; ORDER BY occurances DESC LIMIT 1;</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2005:site.21842-351739</guid>
		<pubDate>Thu, 28 Jul 2005 14:40:46 -0800</pubDate>
		<dc:creator>wackybrit</dc:creator>
	</item><item>
		<title>By: wackybrit</title>
		<link>http://ask.metafilter.com/21842/select-order-by-occurrence-mysql#351745</link>	
		<description>Tested. It works. If you have trouble, let us know.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2005:site.21842-351745</guid>
		<pubDate>Thu, 28 Jul 2005 14:45:11 -0800</pubDate>
		<dc:creator>wackybrit</dc:creator>
	</item><item>
		<title>By: wackybrit</title>
		<link>http://ask.metafilter.com/21842/select-order-by-occurrence-mysql#351746</link>	
		<description>Of course, if I were to be really pendantic to myself, I&apos;d point out it&apos;s &quot;occurrences&quot;.. duh :) I&apos;ll stop posting for a minute now...</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2005:site.21842-351746</guid>
		<pubDate>Thu, 28 Jul 2005 14:46:13 -0800</pubDate>
		<dc:creator>wackybrit</dc:creator>
	</item><item>
		<title>By: oliyoung</title>
		<link>http://ask.metafilter.com/21842/select-order-by-occurrence-mysql#351829</link>	
		<description>An if you want to tack on a limiting clause to an aggregated SQL query, you&apos;ll have to use &quot;HAVING x&quot; instead of &quot;WHERE x&quot; - took me a while to remember that last week ..&lt;br&gt;
&lt;br&gt;
so it&apos;d become &lt;br&gt;
SELECT *, COUNT(desiredcolumn) AS occurances FROM table GROUP BY desiredcolumn HAVING occurances &amp;gt; 5 ORDER BY occurances  DESC LIMIT 1</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2005:site.21842-351829</guid>
		<pubDate>Thu, 28 Jul 2005 16:27:44 -0800</pubDate>
		<dc:creator>oliyoung</dc:creator>
	</item><item>
		<title>By: matildaben</title>
		<link>http://ask.metafilter.com/21842/select-order-by-occurrence-mysql#351889</link>	
		<description>But you don&apos;t need the HAVING occurrences &amp;gt; 5 unless you&apos;re sure that there is a case where there are more than 5 repeats, otherwise you&apos;ll exclude your result if the maxcount happens to be only 4.  Also that clause induces additional calculation overhead.  The LIMIT 1 will do what you originally asked.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2005:site.21842-351889</guid>
		<pubDate>Thu, 28 Jul 2005 18:40:09 -0800</pubDate>
		<dc:creator>matildaben</dc:creator>
	</item>
	</channel>
</rss>
