How to display random 5 images from the database?

Posted by .Netlearner under Sql Server on 6/11/2012 | Points: 10 | Views : 3373 | Status : [Member] | Replies : 5
Hello All,
In ASP.NEt i have to display the random 5 images.Each time i display the page i want 5 random images to be displayed ! Am using SQL Server 2008 as back end. How to select the random 5 image file path from the database.(i have stored image path with the type varchar(100))




Responses

Posted by: Ajay.Kalol on: 6/11/2012 [Member] Starter | Points: 25

Up
0
Down
SELECT TOP 5 IMGPath FROM Table ORDER BY NEWID()



This will give you random Path.

Ajay
ajaypatelfromsanthal.blogspot.in

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: CGN007 on: 6/12/2012 [Member] Silver | Points: 25

Up
0
Down
Syntax
SELECT TOP 5 [column names] FROM [table name] ORDER BY NEWID()


That will get you 5 rows in random order.

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: CGN007 on: 6/12/2012 [Member] Silver | Points: 25

Up
0
Down
Other methods to randomly selecting and ordering rows
http://www.sqlteam.com/tag/randomness

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhsinathk on: 6/15/2012 [Member] Bronze | Points: 25
Posted by: CGN007 on: 6/23/2012 [Member] Silver | Points: 25

Up
0
Down
Mark as Answer if its helpful to you,that motivates...

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response