Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Random() in sqlite and Android sdk

Tags:

android

sqlite

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

like image 207
Cheluis Avatar asked Dec 03 '11 18:12

Cheluis


1 Answers

try this

Cursor cursor = this.db.query("YourTable Order BY RANDOM() LIMIT 1",
                new String[] { "*" }, null, null, null, null, null);
like image 99
Dawid Sajdak Avatar answered Nov 05 '22 05:11

Dawid Sajdak