I want to get distinct values from Database. Currently I am using ORMlite. I have tried the following code. But still I am getting repeated values from, when I am querying. Could anyone point out where I have gone wrong? I am posting the sample code below
smsDao = databaseHelper.getSmsDao();
QueryBuilder<SMSObject, Object> queryBuilder = smsDao.queryBuilder();
queryBuilder.distinct().selectColumns("timestamp");
try {
preparedQuery = queryBuilder.prepare();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
smsObject = smsDao.query(preparedQuery);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Any help is appreciable.
dataList = Utils.getDBHelper(ItemList.this).getItemDao().queryBuilder().where().in("nameid", lis).query();
This is the code I used earlier in my app. It was retrieving duplicate values from the database. Then I updated it with the distinct() method and everything started to work fine.
dataList = Utils.getDBHelper(ItemList.this).getItemDao().queryBuilder().distinct().where().in("nameid", lis).query();
Note: Here 'lis' is the iteratable list in which my search parameters are added. If you don't have one, you can use 'eq()' instead of 'in()'.
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