I want to extract random rows from the app sqlite database in Android. I'm aware that, with sqlite, you can select random rows with:
SELECT * FROM table ORDER BY RANDOM() LIMIT 1;
In the app, I have something like this
return mDb.query(TABLE, new String[] {"col1", "col2"}, null, null, null, null, "Random()", "2");
this is for extract two random rows in table TABLE. But it keeps returning the same rows. What's wrong wit the statement?
Thanks
try this
Cursor cursor = this.db.query("YourTable Order BY RANDOM() LIMIT 1",
new String[] { "*" }, null, null, null, null, null);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With