I have a sqlite
table with the following schema:
CREATE TABLE foo (bar VARCHAR)
I'm using this table as storage for a list of strings.
How do I select a random row from this table?
I have a sqlite
table with the following schema:
CREATE TABLE foo (bar VARCHAR)
I'm using this table as storage for a list of strings.
How do I select a random row from this table?
Here is a modification of @ank's solution:
This solution also works for indices with gaps, because we randomize an offset in a range [0, count).
MAX
is used to handle a case with empty table.Here are simple test results on a table with 16k rows: