←back to thread

Sampling with SQL

(blog.moertel.com)
175 points thunderbong | 2 comments | | HN request time: 0.536s | source
1. indoordin0saur ◴[] No.41904221[source]
For the newbies: quick way I'll get a sample of rows (without weights) in Redshift:

`SELECT * FROM sales ORDER BY RANDOM() LIMIT 10;`

replies(1): >>41904507 #
2. peterm4 ◴[] No.41904507[source]
Been working with sqlite and Typescript, needing random rows sampled reproducibly with a seed. Found this handy little trick [0]. Not the cleanest, but it works!

`SELECT * FROM sales ORDER BY substr(${seedValue} * sales.id, length(sales.id) + 2) LIMIT 10;`

[0] https://stackoverflow.com/questions/24256258/order-by-random...