0

Hi,

Hi I only want to select 5 rows. Can you please tell me how to do it in sql? Thank you.

example:

ratee rater
apple banana
apple orange
apple peach
apple sunkist
apple mango
apple grapes
grapes orange

I want to see random selected of 5 ratee orange with grapes also as ratee.

5
Contributors
4
Replies
42
Views
3 Years
Discussion Span
Last Post by riahc3
0

I am currently working on an app that does something similar, selecting records from a table in Access. The SQL (which I didn't write myself) is basically:

SELECT * FROM ( SELECT TOP 5 * FROM <TableName> [WHERE blah blah blah] ORDER BY Rnd(-(1000*ID)*Time())) ORDER by blah

(ID is a database field.)

1

In MS SQL you can do

SELECT TOP 5 * FROM myTable ORDER BY NEWID()

I believe MySQL has this feature as well. NEWID() generates a globally unique identifier (GUID) in memory for each row. By definition, the GUID is unique and fairly random.

1

in my sql you can set the limit of how many rows you want to show by adding Limit [n] to the query.

Select * from table Limit 5;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.