1

I`m new to GreenDao and want to load a list by stuffId.I need to use Distinct query to prevent duplicate! How can I use distinct in my query? below code does not work!!

@Override
public ArrayList<DbMaterial> loadMaterialStuffList() {
    openReadableDb();
    final List<DbMaterial> materials= mDaoSession.getDbMaterialDao().queryBuilder().distinct()
            .orderDesc(DbMaterialDao.Properties.StuffId).list();
    mDaoSession.clear();
    if (materials != null) {
        return new ArrayList<>(materials);
    }
    return null;
}
Zahra.HY
  • 1,684
  • 1
  • 15
  • 25
  • How you you define duplicates? Check this against the definition of SQL Distinct . – Markus Junginger Jul 04 '16 at 10:02
  • DISTINCT syntax doesn`t operate at all ! – Zahra.HY Jul 05 '16 at 11:43
  • public QueryBuilder distinct() Use a SELECT DISTINCT to avoid duplicate entities returned, e.g. when doing joins.how to use this structure? – Zahra.HY Jul 05 '16 at 11:47
  • Why do you think you are getting duplicates? Please post values including the ID. – Markus Junginger Jul 05 '16 at 18:27
  • I import my database via SQLite Viewer! even I defined stuffId as a unique value and set it as a condition when implement insertOrReplace but I got duplicated values! – Zahra.HY Jul 09 '16 at 11:19
  • [How do I execute “select distinct ename from emp” using GreenDao](http://stackoverflow.com/questions/40575658/how-to-use-distinct-in-greendao) [how to use DISTINCT in GreenDao](http://stackoverflow.com/questions/23445174/how-do-i-execute-select-distinct-ename-from-emp-using-greendao) – 张金富 Jan 11 '17 at 07:55
  • This link may be useful. [How do I execute “select distinct ename from emp” using GreenDao](http://stackoverflow.com/questions/23445174/how-do-i-execute-select-distinct-ename-from-emp-using-greendao) – Dotnetpickles Mar 14 '17 at 10:08

0 Answers0