SQLite - How to select a random row from a SQLite table?
To select a random record from a SQLite table:
SELECT
*
FROM
table_name
ORDER BY
RANDOM()
LIMIT 1;
Or, you can try this:
SELECT
*
FROM
table_name
LIMIT 1 OFFSET ABS(RANDOM()) % MAX((
SELECT
COUNT(*)
FROM table_name), 1)
Each time you execute the query, the result will be different.
Need a good GUI tool for SQLite? Check out TablePlus. It’s native, beautiful, and available for free.
Not on Mac? Download TablePlus for Windows.
On Linux? Download TablePlus for Linux
Need a quick edit on the go? Download TablePlus for iOS