Connecting Tech Pros Worldwide Forums | Help | Site Map

how to retrieve random records from table

Newbie
 
Join Date: Oct 2006
Posts: 1
#1: Oct 9 '06
Hi,
I m doing slideshow application. fro that i m using Ms Sql 7.0 server.
Now i want to retrieve each time 10 different records order by date
(it is the column) from table out of 100 records.
Plz, help me for writing the sql query for this.

Newbie
 
Join Date: Oct 2006
Posts: 2
#2: Oct 9 '06

re: how to retrieve random records from table


Quote:

Originally Posted by pritisarode

Hi,
I m doing slideshow application. fro that i m using Ms Sql 7.0 server.
Now i want to retrieve each time 10 different records order by date
(it is the column) from table out of 100 records.
Plz, help me for writing the sql query for this.

select top 10 * from table order by newid(), mydate
Newbie
 
Join Date: Sep 2008
Posts: 1
#3: Oct 21 '08

re: how to retrieve random records from table


Yes this is correct.

select top 10 * from table order by newid(), orderdate
Delerna's Avatar
Expert
 
Join Date: Jan 2008
Location: Sydney
Posts: 788
#4: Oct 21 '08

re: how to retrieve random records from table


Maybe this is what you mean
Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT TOP 10 a.Field1,a.Field2,a.Field3
  3. FROM
  4. (   SELECT RAND( (DATEPART(mm, GETDATE()) * 100000 )
  5.            + (DATEPART(ss, GETDATE()) * 1000 )
  6.            + DATEPART(ms, GETDATE()) )*100000 as RowPicker,
  7.            YourTable.Field1,YourTable.Field2,YourTable.Field3
  8.    FROM YourTable
  9. )a
  10. ORDER BY RowPicker
  11.  
check out RAND in the help document
Reply