I have a table that contains 50000 lines for example.
I need to select 50 lines from table that contains this 50000 lines, so I need to select every 1000 lines, one line.
for example divide 50000/50, I got 1000 then I must select one line every 1000 lines.
So the query must be dynamic according to the number of lines that I have in the table, and always get my 50 line from different period.
Then the result will have data from all table in different period and different element.
Any help ??
Advertisement
Answer
To select 50 random lines, just use
SELECT * FROM yourtable ORDER BY RAND() LIMIT 50
To select (for example) every 100th line (up to a max of 50), you can use something like
SELECT yourtable.*, @rn:=@rn+1 AS row_number FROM yourtable JOIN (SELECT @rn := 0) r HAVING row_number % 100 = 0 ORDER BY row_number LIMIT 50