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

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -