Query latest models distinct by update_time
See original GitHub issueGoal
I’m converting a sqlite database to Realm and have a model that has fields are groupID and updated_time. I want to select all latest model in each group.
Expected Results
I expect to get the list that contains all latest model sorted by updated_time DESC.
Actual Results
RealmResult.distinct() is deprecated, RealmQuery.distinct() cannot make sure result is latest.
Steps & Code to Reproduce
I don’t have data right now @@
Code Sample
RealmResults<MyModel> realmResults = getRealm().where(MyModel.class)
.notEqualTo(MyModel.GROUP_ID, 0)
.notEqualTo(MyModel.IS_DELETED, 0)
.findAllSorted(MyModel.LAST_UPDATE, Sort.DESCENDING);
realmResults.distinct(MyModel.GROUP_ID); <<< Deprecated
Version of Realm and tooling
Realm version(s): 3.3.1
Realm sync feature enabled: no
Android Studio version: 2.3.3
Which Android version and device: Galaxy Note 5 Android 6.0.1
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (8 by maintainers)
Top Results From Across the Web
Django: filter by latest per distinct column - Stack Overflow
This translates to a SELECT DISTINCT ON SQL query. Here's the difference. For a normal distinct() call, the database compares each field in...
Read more >The SQL SELECT DISTINCT Statement - Laracasts
Hi I want to run a query just give me value with no duplicate. What would be the query in laravel 5 using...
Read more >Selecting distinct values from dupes based on latest date
I have a table of patients that has often multiple occurrences of a patient number but with differing dates of which I need...
Read more >SELECT DISTINCT FROM <model > (DMX) - SQL Server
Returns all possible states for the selected column in the model. The values that are returned vary depending on whether the specified ...
Read more >db.collection.distinct() — MongoDB Manual
A query that specifies the documents from which to retrieve the distinct values. ... When specifying collation, the locale field is mandatory; all...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Tricky question because core needs to be released.
Current core release is 2.8.3, and this would probably be in 2.9.0, which will need to show up in Realm-Java…
This core PR got merged 3 hours ago which allows this use case to work, see https://github.com/realm/realm-core/pull/2644
This means it’ll need to be included in object store and then exposed in Java binding (probably just removing depreciation will be enough though)