-1

I'm trying to figure out the best way to select 10 records randomly from a table for 24 hours the statement should return the same set for 24 hours

SELECT * FROM tableX LIMIT 10

I think i can use the MMDDYY as an input for an algorithm that would take 1 input and return the same set of data for that input. and use that in WHERE or ORDER BY then each day the select will return different data for the next 24 hours.

for example:

I have a table called news i want to be able to select 10 Random news but i don't want the values to change every time the user refresh the page, i want the same news to appear for 24 hours. and next day it will change to another set of random news.

trrrrrrm
  • 11,362
  • 25
  • 85
  • 130

1 Answers1

1

Based on this response, you can select random records from a table with:

SELECT * FROM table ORDER BY RAND() LIMIT 10;

According to MySql doc, the function RAND() can take a seed as an argument.

So you should use:

 SELECT * FROM table ORDER BY RAND(yyyymmdd) LIMIT 10;

where yyyymmdd is an integer representing the date.

Community
  • 1
  • 1
obourgain
  • 8,856
  • 6
  • 42
  • 57