Tuesday 23 January 2018

How to sample rows in MySQL using RAND(seed)?

Use the same seed for all the rows to do that, like:
select id from foo where rand(42) < 0.05 order by id desc limit 100
See the rand() docs for why it works that way. Change the seed if you want another set of values.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.