Select a random row using SQLite

Hi. I have a database like this:
Question,Correct_Answer,Wrong_Answer1,Wrong_Answer2,Wrong_Answer3 , 5 columns and 3 lines.
I want to make a function to use the information from a random row.

I want something like this.
I use math.random(firstline, last line)
Then , I put all the information from that row, such as Question,Correct_Answer,Wrong_Answer1,Wrong_Answer2,Wrong_Answer3 in different variables.

I tried and tried , but I didn’t succed.
Thanks. [import]uid: 178587 topic_id: 31766 reply_id: 331766[/import]

IMO, unless your database is really, really huge I would just read all of your data into a Lua table. From there it’s super easy to get a random row.

myTable[math.random(table.getn(myTable))]
Lua table api is message easier to deal with them SQLite api. [import]uid: 147305 topic_id: 31766 reply_id: 126814[/import]

I am not sure if I understand your question, but you want a random recordset from your table?

select * from [your_table_name] ORDER BY RANDOM() limit 1

Joakim [import]uid: 81188 topic_id: 31766 reply_id: 126816[/import]

NahirC helped me on #corona.
“SELECT * FROM SQL where id =”… math.random(1,id_max) works perfect!
Thank you both. [import]uid: 178587 topic_id: 31766 reply_id: 126820[/import]

IMO, unless your database is really, really huge I would just read all of your data into a Lua table. From there it’s super easy to get a random row.

myTable[math.random(table.getn(myTable))]
Lua table api is message easier to deal with them SQLite api. [import]uid: 147305 topic_id: 31766 reply_id: 126814[/import]

I am not sure if I understand your question, but you want a random recordset from your table?

select * from [your_table_name] ORDER BY RANDOM() limit 1

Joakim [import]uid: 81188 topic_id: 31766 reply_id: 126816[/import]

NahirC helped me on #corona.
“SELECT * FROM SQL where id =”… math.random(1,id_max) works perfect!
Thank you both. [import]uid: 178587 topic_id: 31766 reply_id: 126820[/import]