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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -