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

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.