﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / T-SQL (SS2K8)  / random records / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Thu, 23 May 2013 11:01:38 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: random records</title><link>http://www.sqlservercentral.com/Forums/Topic1035673-392-1.aspx</link><description>[quote][b]The Dixie Flatline (12/17/2010)[/b][hr]Note to Jeff Moden: It may not be "Nasty Fast" but it's "Wicked Quick" [/quote]Heh... too funny, Bob. :-D</description><pubDate>Fri, 17 Dec 2010 18:57:23 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: random records</title><link>http://www.sqlservercentral.com/Forums/Topic1035673-392-1.aspx</link><description>Here is an example of pulling 20 random rows from a million row table.Note to Jeff Moden:   It may not be "Nasty Fast" but it's "Wicked Quick" :-DHad to make this an attachment.   For some reason, SSC is blocking my posts.</description><pubDate>Fri, 17 Dec 2010 11:53:16 GMT</pubDate><dc:creator>The Dixie Flatline</dc:creator></item><item><title>RE: random records</title><link>http://www.sqlservercentral.com/Forums/Topic1035673-392-1.aspx</link><description>Using ORDER BY NEWID() with huge files is slow, because of the sort time.Generating TOP (X) WHERE (random number test) is fast, but tends to skew towards the front of the table, whatever that may be.If you have an indexed IDENTITY (ID) column in your primary table, I would generate a temp table of 10-20 distinct random numbers between min(ID) and max(ID) and join it to the primary.</description><pubDate>Thu, 16 Dec 2010 17:10:44 GMT</pubDate><dc:creator>The Dixie Flatline</dc:creator></item><item><title>RE: random records</title><link>http://www.sqlservercentral.com/Forums/Topic1035673-392-1.aspx</link><description>Here is another method I've seen/used that is pretty similar to the ORDER BY NEWID(), but much faster:[code="sql"]SELECT TOP 10 * FROM MyTableWHERE 0.01 &amp;gt;= CAST(CHECKSUM(NEWID(), SomeColumnName) &amp; 0x7fffffff AS float) / CAST (0x7fffffff AS int) [/code]NOTE: Repalce "SomeColumnName" with some columns or set of columns from your table, PKs work well.</description><pubDate>Thu, 16 Dec 2010 16:17:04 GMT</pubDate><dc:creator>Lamprey13</dc:creator></item><item><title>RE: random records</title><link>http://www.sqlservercentral.com/Forums/Topic1035673-392-1.aspx</link><description>What about the TABLESAMPLE clause?EG.[code="sql"]  SELECT *  FROM tableX  TABLESAMPLE (10 percent)[/code]More info [url=http://www.mssqltips.com/tip.asp?tip=1308]here[/url]</description><pubDate>Thu, 16 Dec 2010 03:42:58 GMT</pubDate><dc:creator>grahamc</dc:creator></item><item><title>RE: random records</title><link>http://www.sqlservercentral.com/Forums/Topic1035673-392-1.aspx</link><description>[quote][b]Sachin Nandanwar (12/16/2010)[/b][hr]Use Top clause without order by clause.Select top 10 columnname from yourtable.[/quote]This would mostly give the same result again and again. Use NEWID() in the ORDER BY Clause[code="sql"]SELECT TOP 10 * FROM YourTable ORDER BY NEWID()[/code]</description><pubDate>Thu, 16 Dec 2010 02:05:10 GMT</pubDate><dc:creator>Kingston Dhasian</dc:creator></item><item><title>RE: random records</title><link>http://www.sqlservercentral.com/Forums/Topic1035673-392-1.aspx</link><description>Use Top clause without order by clause.Select top 10 columnname from yourtable.</description><pubDate>Thu, 16 Dec 2010 01:38:29 GMT</pubDate><dc:creator>Sachin Nandanwar</dc:creator></item><item><title>random records</title><link>http://www.sqlservercentral.com/Forums/Topic1035673-392-1.aspx</link><description>How to select random (10 or 20) records from table?</description><pubDate>Thu, 16 Dec 2010 00:42:47 GMT</pubDate><dc:creator>ranadip.dey</dc:creator></item></channel></rss>