0

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.

Rajeev Mehta
  • 820
  • 2
  • 10
  • 32

3 Answers3

3

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

SELECT TOP(5) * FROM tbl_Employees ORDER BY NEWID()
Pawan
  • 1,704
  • 1
  • 16
  • 37
1
select top 5 * from [yourtable] order by newid()
Moshtaf
  • 4,833
  • 2
  • 24
  • 34
1
select  top(5) * from tbl_Employees order by newid()
Genish Parvadia
  • 1,437
  • 3
  • 17
  • 30