Rajeev Mehta
Rajeev Mehta

Reputation: 820

Random records Select in mysql

I have a table name tbl_Employees

id  Name    Designation
1   Rajeev  Developer
2   Deepak  Developer
3   Pankaj  Sales
4   Siksha  Sales
5   Parul   Sales
6   Nikita  HR
7   Dinesh  Account
8   Mahiman Travel
9   Mukesh  Adevertising
10  Pulkit  Marketing
11  Diksha  Database
12  Gurinder    Database

I am using the select query as

select  * from tbl_Employees

Now I am trying to show 5 rows on my .aspx page. now my query is that the 5 rows data is randomly change on every PageLoad event.

Upvotes: 0

Views: 197

Answers (3)

Genish Parvadia
Genish Parvadia

Reputation: 1455

select  top(5) * from tbl_Employees order by newid()

Upvotes: 1

Moshtaf
Moshtaf

Reputation: 4903

select top 5 * from [yourtable] order by newid()

Upvotes: 1

Pawan
Pawan

Reputation: 1744

You can use NEWID() to select records rendomly as below:

SELECT TOP(5) * FROM tbl_Employees ORDER BY NEWID()

Upvotes: 3

Related Questions