select 1 random number from mysql database using asp.net c# -


how can select 1 random number database thats id autoincrement field.i have 25,000[id] records in database.each every time select 1 new random id. how can it.

use following sql(slow)

'select * tablename order rand() limit 1' 

or can use(fast)

select * mytable, (select floor(max(mytable.id) * rand()) randid mytable) somerandid mytable.id = somerandid.randid  

the inner select gives random id in right range. outer select looks right row in table.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -