Possible Duplicate:
SQL Server Random Sort
I guess it sounds stupid but I want to retrieve a few records randomly each time user refreshes the page. is there any Query available for SQL Server 2005 to do that or should I do this in page?
Possible Duplicate:
SQL Server Random Sort
I guess it sounds stupid but I want to retrieve a few records randomly each time user refreshes the page. is there any Query available for SQL Server 2005 to do that or should I do this in page?
Try this:
SELECT TOP 10 Field1, ..., FieldN FROM Table1 ORDER BY NEWID()
NEWID() creates a unique value of uniqueidentifier type. Take a look at this.
Hope it helps.
Yes, there is
I don't know about SQL Server but seeing as SQL is meant to be standardised, you could try the MySQL way: As far as I can remember you just have to use a MySQL function, rand() to sort your SELECT call and then limit the length to 1, so as to get only the first result.
SELECT * FROM tableName ORDER BY rand() LIMIT 1
Give that a go, hope it helps!