Skip to content Skip to sidebar Skip to footer

Android Room Database, Retrieve Specific Value Of The Latest Record Entered

I have used Android Room Database to create my app, I am filling records of students, I want to retrieve page number of the latest record that I have entered from the Room Database

Solution 1:

You just need to create a new Query to fetch what you need.

From what you say you want to find record from one student and display the last page he reads so it should be something like this

@Query("SELECT * FROM newRecord_table WHERE newRecord_table.studentid = :studentId ORDER BY newRecord_table.date, newRecord_table.page DESC ")
LiveData<List<NewRecord>> findLastPage(Integer studentId);

studentId is the userId you want to find the records. Don't forget to handle the case where there is nothing.

Post a Comment for "Android Room Database, Retrieve Specific Value Of The Latest Record Entered"