Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get random record in SQLite

I fetch records in my SQLite database like this.

spellId = extra.getString("spellId");
DBase db = new DBase(this);
db.open();
String[] data = db.getRecord(Integer.parseInt(spellId));
db.close();

Can I get random data like this without using raw queries and cursor?

like image 400
Suika Avatar asked Jan 31 '15 07:01

Suika


1 Answers

try like this:

db.rawQuery("SELECT * FROM mainTable ORDER BY RANDOM() LIMIT 1", null);
like image 178
No Name Avatar answered Sep 25 '22 14:09

No Name