Skip to content

RANDOM

CREATE TABLE numbers (num INTEGER);
INSERT INTO numbers (num)
VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
SELECT *
FROM numbers
ORDER BY RANDOM()
LIMIT 1;
num
---
4

In the example provided, a table named ‘numbers’ is being created and populated with integers 1 through 10. The ‘SELECT’ statement is being used to retrieve all records from this table. The ‘ORDER BY RANDOM()’ function randomizes the order of the records, and the ‘LIMIT 1’ clause picks just one record from this random output, effectively picking a random number from 1 to 10. The output shown is an example where ‘4’ was the randomly selected number.