0

I am querying a mysql database to plot some of the variables. I would like to limit the no of points read to a fixed number, say 3000.

So if a table has more than 3000 rows (say it has 6000 rows), I would like to read the 1,3,5,7 th row etc, so that the chart made with the data has 3000 points but is still representative of the dataset. I think the LIMIT keyword may not be appropriate if it selects contiguous rows at any location.

How can this be done?

Thanks DY

user3259040
  • 155
  • 1
  • 11
  • does it have to be exact interval? If you're just looking to sample, just order by rand limit 3000 – CrayonViolent Mar 31 '14 at 21:11
  • Thanks. A periodic sampling would be nice, but in the absence of that solution, I could do as you suggest(random and limit) – user3259040 Mar 31 '14 at 21:23
  • 1
    http://stackoverflow.com/questions/858746/how-do-you-select-every-n-th-row-from-mysql – CrayonViolent Mar 31 '14 at 21:24
  • http://dba.stackexchange.com/questions/56168/select-every-n-th-row-dont-pull-the-entire-table might be a more efficient, albeit more complex solution. It even references the first link I found. – CrayonViolent Mar 31 '14 at 21:30
  • You can generate a sequence number on the rows in a subquery, and then select only the rows where the sequence matches a pattern (ie, for every other one, `MOD(@seq, 2) = 1` ) – Kickstart Mar 31 '14 at 22:04

0 Answers0