
In SQLite, you can randomly get one or multiple rows from a table by using the following select statement:
SELECT column1, column2, ...
FROM <table name>
ORDER BY RANDOM()
LIMIT <number of rows you want>;Example
Let’s say we have a table named users:
| Column | Data Type |
|---|---|
| id | INTEGER |
| TEXT | |
| name | TEXT |
| password | TEXT |
If we want to retrieve 10 (you can get less than 10 results if the table doesn’t have enough data) users at random:
SELECT *
FROM users
ORDER BY RANDOM()
LIMIT 10;See also: Flutter & SQLite: CRUD Example.
Happy coding.