How to select random record form Database table ?

Posted by Ksuresh under Sql Server on 4/11/2012 | Points: 10 | Views : 2737 | Status : [Member] | Replies : 7
Hi every one,

I want at each time one record randomly from my dtable , how can i achieve this? Please help me..

Thanks
Suresh




Responses

Posted by: Hariinakoti on: 4/11/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Suresh,
u can use this query. i think it is help ful to u.
ex:
SELECT TOP 10 OrderID, NewID() as Random
FROM Orders
ORDER BY Random



Thanks & Regards
Hari

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

Posted by: Rajni.Shekhar on: 4/11/2012 [Member] Bronze | Points: 25

Up
0
Down
use following link:

http://msdn.microsoft.com/en-us/library/cc441928.aspx

Thanks,
Rajni Shekhar

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

Posted by: Ksuresh on: 4/11/2012 [Member] Starter | Points: 25

Up
0
Down
Thank you Hariinakoti ,

Your Query working, in my table more than thousand records are there, by clicking on Next button on my page i am getting one record from table randomly, its ok. but some of records(4 to 5) appearing repeatedly, i don't want to repeat records , can you know how to solve this issue, please help me....

Thank you
Suresh

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

Posted by: Hariinakoti on: 4/11/2012 [Member] Starter | Points: 25

Up
0
Down
hi suresh ,
u can use distinct.Then there is not take duplicate values.
it'll work..

Thanks & Regards
Hari

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

Posted by: Sakthi.Singaravel on: 4/11/2012 [Member] Silver | Points: 25

Up
0
Down
thank u Hari,

its useful for me..

Regards,
Singaravel M

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

Posted by: Kamalakanta.Nayak09 on: 4/23/2012 [Member] Starter | Points: 25

Up
0
Down
Where/In which case we use the NewID() in Sql Server ?

Thanks,
K.K

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

Posted by: Sakthi.Singaravel on: 4/24/2012 [Member] Silver | Points: 25

Up
0
Down
@Kamalakant Nayak

NEWID() Creates a unique value of type uniqueidentifier

Regards,
Singaravel M

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

Login to post response