Skip to content

Instantly share code, notes, and snippets.

@codeactual
Forked from swayson/sqlite_random_sample.sql
Created February 27, 2023 22:34
Show Gist options
  • Save codeactual/d037605d6ff42e465adcfbb6641921ac to your computer and use it in GitHub Desktop.
Save codeactual/d037605d6ff42e465adcfbb6641921ac to your computer and use it in GitHub Desktop.
Efficient way to do random sampling in SQLite.
SELECT * FROM table
WHERE _ROWID_ >= (abs(random()) % (SELECT max(_ROWID_) FROM table))
LIMIT 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment