I am working on PHP. I was working with MySQL before. Here is the code I used –
$offset_result = mysqli_query($con, " SELECT FLOOR(RAND() * COUNT(*)) AS `offset` FROM students ");
$offset_row = mysqli_fetch_object( $offset_result );
$offset = $offset_row->offset;
$result = mysqli_query($con, " SELECT name FROM students LIMIT $offset, 1 " );
$row = mysqli_fetch_row($result);
mysqli_free_result($result);
What will be the corresponding set of statements for SQLite?
Those SQL queries should work in SQLite if you just change
RANDtoRANDOMandFLOOR(x)toCAST(x AS INTEGER).A slightly simpler way to do it is to order by a random number:
The way you are doing it is more efficient if the table is very large.