473,385 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how to retrieve random records from table

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
3 2664
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
Yes this is correct.

select top 10 * from table order by newid(), orderdate
Oct 21 '08 #3
Delerna
1,134 Expert 1GB
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

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

Similar topics

3
by: Wim Roffil | last post by:
Hi, When I do a select with a limit I get always the same records. Usually this is the desidered effect. But now I want to do a random select. So every time I do a select I should get a...
3
by: jaYPee | last post by:
anyone know how can i get a 10% random records out of 2000 records? 2000 is only an example and it will vary anytime. i want to create a report out of this 10% thanks in advance
4
by: yf | last post by:
A KB article "http://support.microsoft.com/default.aspx?scid=kb;en-us;209599" tells that the maximum number of records that a table may hold if the PRIMARY key data type is set to AUTONUMBER is...
2
by: IceCube | last post by:
Hello, I would like to select/filter at random 30 records out of an Access-table of 1500 records. I know the option "Top" which gives me the possibility to see the 30 first records of the table...
12
by: jaYPee | last post by:
I have currently using a dataset to access my data from sql server 2000. The dataset contains 3 tables that is related to each other. parent/child/grandchild relationship. My problem is it's very...
9
by: Jeremy | last post by:
I have a situation where i am trying to run two query's and retrieve one record from each query, then using Union combine them into one recordset. The First Query is strait forward and should just...
13
by: kev | last post by:
Hi all, I have created a database for equipments. I have a form to register the equipment meaning filling in all the particulars (ID, serial, type, location etc). I have two buttons at the end...
5
by: muskie | last post by:
I've looked through as many posts about this as possible, but all end with no resolution. I simply need records from a table in random order, and I will be calling this recordset in a SQL...
4
by: LetMeDoIt | last post by:
Greetings, I'm using ASP to retrieve from MSSQL and I then populate a table. After several months of successfull retrieves, this same code now bombs out. It turns out that if I clear out from...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.