Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to query from realm database with distinct results java

I have got a Realm object class, and storing lots of data in there, imagine that I have a String uid; field. I want to get uid names, but on same uid names just only one time, For example

uid

AA

AA

BB

CC

DD

BB

BB

I want to get just AA,

BB,

CC,

DD.

Only one time. I looked over realm documentation but couldn't find anything.

Thanks for answers.

like image 728
Mucahit Avatar asked Jun 22 '15 11:06

Mucahit


1 Answers

UPDATED :

You can use distinct() to get distinct entries for an object class.

// Returns the set of users that all have a different name
RealmResults<User> users = realm.where(User.class).distinct("name");

Note: .distinct will only work on fields that are indexed (@Index or @PrimaryKey). It doesn't work with child object property.

You can find more information about this method here in the official documentation. https://realm.io/docs/java/latest/api/io/realm/Realm.html#distinct-java.lang.Class-java.lang.String-][1]

like image 122
Kingston Avatar answered Oct 11 '22 20:10

Kingston