How to get a sample of random rows in redshift using SQL alchemy efficiently

1.4k Views Asked by At

Theres a data set of size 200M how to get random sample data(of size 100rows) efficiently using SQLalchemy or any other possible way.

1

There are 1 best solutions below

0
edwardmoradian On BEST ANSWER
SELECT * 
FROM sales
ORDER BY RANDOM()
LIMIT 10;

With random every row has an equal chance of being selected. Use Limit to choose how many rows to return.

Reference: https://docs.aws.amazon.com/redshift/latest/dg/r_RANDOM.html