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.

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.)

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.

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;

Even better:

select * from table limit 1,5;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.