By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,290 Members | 1,253 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,290 IT Pros & Developers. It's quick & easy.

how to retrieve random records from table

P: 1
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.
Oct 9 '06 #1
Share this Question
Share on Google+
3 Replies


P: 2
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
Oct 9 '06 #2

P: 1
Yes this is correct.

select top 10 * from table order by newid(), orderdate
Oct 21 '08 #3

Delerna
Expert 100+
P: 1,134
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
Oct 21 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.