Unix Technical Forum

random row

This is a discussion on random row within the SQL Server forums, part of the Microsoft SQL Server category; --> Hi there. I need to fetch ONE random row from many. How can i get it? I try to ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 05:24 AM
anuke@bk.ru
 
Posts: n/a
Default random row

Hi there.
I need to fetch ONE random row from many. How can i get it? I try to
execute "SELECT field.table FROM table ORDER by RAND()" no effect.
Thank you.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 05:24 AM
Simon Hayes
 
Posts: n/a
Default Re: random row


<anuke@bk.ru> wrote in message
news:e23cb98a.0409290437.40d62abc@posting.google.c om...
> Hi there.
> I need to fetch ONE random row from many. How can i get it? I try to
> execute "SELECT field.table FROM table ORDER by RAND()" no effect.
> Thank you.


See this code sample:

http://vyaskn.tripod.com/code.htm#rand

Or this is another possiblity, but MSSQL needs to scan the whole table, so
it will be slow on large tables:

select top 1 *
from table
order by newid()

Simon


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:22 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com