DISTINCT
In my usage, there are various times where I only want one out of a set of objects that share a value of a field - much like the 'DISTINCT' clause in SQL. For exampe, with the items
| name | logInTime |
|---|---|
| Bill | 1426270572 |
| Mark | 1426272004 |
| Mark | 1426273505 |
| Mark | 1426274666 |
| Sally | 1426268301 |
| Sally | 1426271123 |
in the table 'User', realm.where(User.class).distinct("name").findAll() would return 3 items (one for 'Mark', one for 'Bill', and one for 'Sally'). With it like this, which 'Mark' and which 'Sally' is undefined - presumably the first one Realm finds.
A potential advanced aspect of this would be to select which of the rows to return. realm.where(User.class).distinct("name", "logInTime", false).findAll() would return (Bill, 1426270572), (Mark, 1426274666), (Sally,1426271123), or only having the first discovered in an sorted RealmResult appear.
The first part sounds very much like the DISTINCT keyword in SQL, is that correct? We actually have support for that in the core database, but it havn't been exposed yet in the Java query language.
The second part is harder to express in a succinct way, so it is a use case to consider, but it will most likely complicate the query language too much compared to how many people would actually use it.
Right, don't know what I was thinking. Modified
Do we have a timeline for this one? thanks!
+1
+1
+1 :(
As #1566 only implements Realm.distinct(), a new issue (#1568) is created for tracking RealmResults.distinct().