PDA

View Full Version : Sql/Asp random record display


jaywhy13
02-11-2005, 04:04 PM
NB: lemme just say I've done my home work.... I've already done a forum search

Okay... I'd like to display a couple random records from a table. I don't want to retrieve the entire table.... lets just say to use the entire table is equivalent to hoggin the server unnecessarily. And in the post I found in search they ran too queries... One retrieving the whole table and then the second was finding the max record and then running a random algorithm from there.

But :o I don't wanna do it that way. Like I said, it'd be unnecessarily hoggin the server and I don't want that. So I was thinking there must be a syntax or some tip or trick that can get me some random records from the table....

waolly
02-11-2005, 06:10 PM
Hi,

The code below should do what you require - it selects one random record from a table. Note it is important to multiply by a <column> value so that each row generates a different seed for the rand function.


select top 1 *
from <table>
order by rand (10.0 * <column> * datepart(ms, current_timestamp))