Reputation: 4175
I am trying to get a random order by using Order by NEWID()
as the following:
public Cursor getSpecialList(String bloodCategory) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cur = db.rawQuery("SELECT " + colName + " ," +
"" + colFather + " ," +
"" + colFamily + " ,"+
"" + colPhone + " from " + ListInfoTable +
" WHERE " + colBloodCategory + "='" + bloodCategory + "'" +
" order by NEWID() ", new String[]{});
return cur;
}
SQLite Log gives me the following error:
No such function NEWID
Upvotes: 0
Views: 2096
Reputation: 827
You can use following code for random data:
public Cursor getSpecialList(String bloodCategory )
{
SQLiteDatabase db=this.getReadableDatabase();
Cursor cur=db.rawQuery("SELECT "+colName+" ,"+
""+colFather+" ,"+
""+colFamily+" ,"+
""+colPhone+" from "+ListInfoTable+
" WHERE "+colBloodCategory+"='"+bloodCategory+"'"+
" ORDER BY RANDOM() ",new String[] {});
return cur;
}
Upvotes: 1