<?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: How to produce random rows from a table</title> <atom:link href="http://www.mysqldiary.com/how-to-produce-random-rows-from-a-table/feed/" rel="self" type="application/rss+xml" /><link>http://www.mysqldiary.com/how-to-produce-random-rows-from-a-table/</link> <description>Exploring, Sharing and  Discussing MySQL practice</description> <lastBuildDate>Thu, 02 Feb 2012 09:16:49 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>By: Amit S</title><link>http://www.mysqldiary.com/how-to-produce-random-rows-from-a-table/comment-page-1/#comment-3507</link> <dc:creator>Amit S</dc:creator> <pubDate>Sun, 31 Jul 2011 16:19:59 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=20#comment-3507</guid> <description>Interesting solution. I was wondering my this algorithm is not the native implementation in the ORDER BY RAND() function in MySql.</description> <content:encoded><![CDATA[<p>Interesting solution. I was wondering my this algorithm is not the native implementation in the ORDER BY RAND() function in MySql.</p> ]]></content:encoded> </item> <item><title>By: sagi baron</title><link>http://www.mysqldiary.com/how-to-produce-random-rows-from-a-table/comment-page-1/#comment-3109</link> <dc:creator>sagi baron</dc:creator> <pubDate>Tue, 15 Feb 2011 12:05:34 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=20#comment-3109</guid> <description>You can get &lt;strong&gt;a very efficient way&lt;/strong&gt; to produce random rows from MySQL table by using the RAND function in the WHERE clause and not in the ORDER BY clause.
It is returning random rows very fast and there is no need to worry about holes in the table&#039;s ids:
See &lt;a href=&quot;http://www.rndblog.com/how-to-select-random-rows-in-mysql/&quot; rel=&quot;nofollow&quot;&gt;how to select random rows in mysql&lt;/a&gt;</description> <content:encoded><![CDATA[<p>You can get <strong>a very efficient way</strong> to produce random rows from MySQL table by using the RAND function in the WHERE clause and not in the ORDER BY clause.<br
/> It is returning random rows very fast and there is no need to worry about holes in the table&#8217;s ids:<br
/> See <a
href="http://www.rndblog.com/how-to-select-random-rows-in-mysql/" rel="nofollow">how to select random rows in mysql</a></p> ]]></content:encoded> </item> <item><title>By: RL</title><link>http://www.mysqldiary.com/how-to-produce-random-rows-from-a-table/comment-page-1/#comment-3013</link> <dc:creator>RL</dc:creator> <pubDate>Sun, 06 Feb 2011 04:39:45 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=20#comment-3013</guid> <description>I assume you used MyISAM tables for this solution? MyISAM stores the row counts in meta-information for each table... using COUNT(*) on other database engines may be a lot slower.</description> <content:encoded><![CDATA[<p>I assume you used MyISAM tables for this solution? MyISAM stores the row counts in meta-information for each table&#8230; using COUNT(*) on other database engines may be a lot slower.</p> ]]></content:encoded> </item> <item><title>By: Michael</title><link>http://www.mysqldiary.com/how-to-produce-random-rows-from-a-table/comment-page-1/#comment-2776</link> <dc:creator>Michael</dc:creator> <pubDate>Fri, 14 Jan 2011 15:08:45 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=20#comment-2776</guid> <description>The workaround for the ORDER BY RAND()
its to add in where clause Rand
Example:
select * from mytbl where RAND()&gt;0.9 ORDER BY RAND()</description> <content:encoded><![CDATA[<p>The workaround for the ORDER BY RAND()<br
/> its to add in where clause Rand</p><p>Example:<br
/> select * from mytbl where RAND()>0.9 ORDER BY RAND()</p> ]]></content:encoded> </item> <item><title>By: Justin</title><link>http://www.mysqldiary.com/how-to-produce-random-rows-from-a-table/comment-page-1/#comment-2754</link> <dc:creator>Justin</dc:creator> <pubDate>Tue, 16 Nov 2010 05:51:12 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=20#comment-2754</guid> <description>I&#039;ve another solution, the problem I had with the solutions presented was extremely large and ramdom gaps in my index field, and the need to select not just one random row, but 50, and the need to use a where clause as well (selecting random records matching something else or other in the table). order by rand works but gets very slow when the table is huge and requires a sort.
My solution is to create a temporary table, which is effectively an view of the key field of the target table with a primary key that is auto_indexed. You can create this table in one like &quot;create temporary view_table (id int auto_increment primary key, i) as select (i) from big_table where ...&quot;
then I create a list of random numbers between 0 and the number of rows in that temporary table and then do a join
select blah from big_table,view_table where view_table.id IN ($list) and view_table.i = big_table.i
and that&#039;s it. Very fast.
Now and again (daily, hourly, whatever) drop the temporary table and re-create it.</description> <content:encoded><![CDATA[<p>I&#8217;ve another solution, the problem I had with the solutions presented was extremely large and ramdom gaps in my index field, and the need to select not just one random row, but 50, and the need to use a where clause as well (selecting random records matching something else or other in the table). order by rand works but gets very slow when the table is huge and requires a sort.</p><p>My solution is to create a temporary table, which is effectively an view of the key field of the target table with a primary key that is auto_indexed. You can create this table in one like &#8220;create temporary view_table (id int auto_increment primary key, i) as select (i) from big_table where &#8230;&#8221;</p><p>then I create a list of random numbers between 0 and the number of rows in that temporary table and then do a join</p><p>select blah from big_table,view_table where view_table.id IN ($list) and view_table.i = big_table.i</p><p>and that&#8217;s it. Very fast.</p><p>Now and again (daily, hourly, whatever) drop the temporary table and re-create it.</p> ]]></content:encoded> </item> <item><title>By: Bruce</title><link>http://www.mysqldiary.com/how-to-produce-random-rows-from-a-table/comment-page-1/#comment-916</link> <dc:creator>Bruce</dc:creator> <pubDate>Fri, 21 May 2010 03:26:18 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=20#comment-916</guid> <description>Wow... interesting information.</description> <content:encoded><![CDATA[<p>Wow&#8230; interesting information.</p> ]]></content:encoded> </item> <item><title>By: Hazan Ilan</title><link>http://www.mysqldiary.com/how-to-produce-random-rows-from-a-table/comment-page-1/#comment-688</link> <dc:creator>Hazan Ilan</dc:creator> <pubDate>Mon, 10 May 2010 08:09:03 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=20#comment-688</guid> <description>Hi bdwankhede,
1. As far as I know (correct me if I&#039;m wrong), there is no &quot;FIRST&quot; aggregate function in MySql, so you need to check the performance of it.
2. Please send me the Explain.
3. If “inspections” table is a big one, the ORDER BY RAND() is known to be a performance consumer. Please tell how much rows you have.
4. You can try selecting 1000 random records from “inspections” first and LEFT JOIN only on the results.
Waiting for your response
Ilan.</description> <content:encoded><![CDATA[<p>Hi bdwankhede,<br
/> 1. As far as I know (correct me if I&#8217;m wrong), there is no &#8220;FIRST&#8221; aggregate function in MySql, so you need to check the performance of it.<br
/> 2. Please send me the Explain.<br
/> 3. If “inspections” table is a big one, the ORDER BY RAND() is known to be a performance consumer. Please tell how much rows you have.<br
/> 4. You can try selecting 1000 random records from “inspections” first and LEFT JOIN only on the results.</p><p>Waiting for your response<br
/> Ilan.</p> ]]></content:encoded> </item> <item><title>By: bdwankhede</title><link>http://www.mysqldiary.com/how-to-produce-random-rows-from-a-table/comment-page-1/#comment-614</link> <dc:creator>bdwankhede</dc:creator> <pubDate>Tue, 04 May 2010 03:28:33 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=20#comment-614</guid> <description>i have a query on Firebird sql as
SELECT FIRST 1000 i.&quot;id&quot;, i.&quot;slug&quot;, i.&quot;what_they_do&quot;, i.&quot;does_well&quot;, i.&quot;last_improves&quot; FROM &quot;inspections&quot; i LEFT JOIN &quot;services&quot; s on i.&quot;service_id&quot; = s.&quot;id&quot; WHERE s.&quot;active&quot; = 1 AND s.&quot;suspended&quot; = 0 AND i.&quot;report_date&quot; &gt; &#039;2005-04-01&#039; ORDER BY RAND() ASC;
and it executes very slow , Please help...</description> <content:encoded><![CDATA[<p>i have a query on Firebird sql as</p><p>SELECT FIRST 1000 i.&#8221;id&#8221;, i.&#8221;slug&#8221;, i.&#8221;what_they_do&#8221;, i.&#8221;does_well&#8221;, i.&#8221;last_improves&#8221; FROM &#8220;inspections&#8221; i LEFT JOIN &#8220;services&#8221; s on i.&#8221;service_id&#8221; = s.&#8221;id&#8221; WHERE s.&#8221;active&#8221; = 1 AND s.&#8221;suspended&#8221; = 0 AND i.&#8221;report_date&#8221; &gt; &#8217;2005-04-01&#8242; ORDER BY RAND() ASC;</p><p>and it executes very slow , Please help&#8230;</p> ]]></content:encoded> </item> <item><title>By: Amsterdam Escort</title><link>http://www.mysqldiary.com/how-to-produce-random-rows-from-a-table/comment-page-1/#comment-602</link> <dc:creator>Amsterdam Escort</dc:creator> <pubDate>Thu, 29 Apr 2010 21:44:43 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=20#comment-602</guid> <description>I enjoyed viewing your blog and I will be back to check it more in the future so please keep up your good quality work. I love the colors that you chose, you are quite talented!</description> <content:encoded><![CDATA[<p>I enjoyed viewing your blog and I will be back to check it more in the future so please keep up your good quality work. I love the colors that you chose, you are quite talented!</p> ]]></content:encoded> </item> <item><title>By: Bernarda Ocon</title><link>http://www.mysqldiary.com/how-to-produce-random-rows-from-a-table/comment-page-1/#comment-598</link> <dc:creator>Bernarda Ocon</dc:creator> <pubDate>Thu, 29 Apr 2010 07:30:36 +0000</pubDate> <guid
isPermaLink="false">http://www.mysqldiary.com/?p=20#comment-598</guid> <description>Wow... interesting information.</description> <content:encoded><![CDATA[<p>Wow&#8230; interesting information.</p> ]]></content:encoded> </item> </channel> </rss>
