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
Post a Comment