Jump to content

best way to select random row of database of 100k+ in size


krispykreme

Recommended Posts

random selection of one row is what i want right now

 

no filtering needed, but in the future i want to be able to randomly select from a user that has been offline for 24 hours givin a time contraint

 

what would be the best way to do this?  ive never done a random selection in a query so i want to be guided to the best way from the start

a hackisk way to get it done, would be to get the amount rows in the table, like "select row_id from table where order by row_id DESC limit 0,1";

 

then do a "select * from table where row_id = " . rand(0,$row_id) . "' limit 0,1";

($row_id would be the row_id from the first query).

 

As i said, it's a hackish way, i'm quite sure there is a better way to do it thou.

 

PS, this assumes you have a row_id and it's in some type of order.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.