I'm using Spring Data JPA and I would like to retrieve the last record from Settings
table.
I have SettingsRepository
with standard methods implemented by Spring Data. How to write a method (or a query) to retrieve last row from the given table?
interface SettingsRepository extends JpaRepository<Settings, Long> { // ? }
Get the last record from a table in MySQL database with Java? To get data from MySQL database, you need to use executeQuery () method from java. First create a table in the MySQL database. Here, we will create the following table in the ‘sample’ database Now you can insert some records in the table using insert command.
There is no specific function to get the last record. You can, however, order in reverse (DESC on ID, for example - assuming there's an ID) and get the first record. Not the answer you're looking for? Browse other questions tagged java spring spring-data-jpa spring-data or ask your own question.
On the basis of descending order of id value, we can get the last row from table. $last_row = DB::table ('students')->orderBy ('id', 'DESC')->first (); We hope this article helped you to learn How To Get Last Record of Database Table in Laravel 8 Tutorial in a very detailed way. Online Web Tutor invites you to try Skillshare free for 1 month!
4.if flag is set read the table with the count as index. Hope this might help you out. make the use of sy-dbcnt below the select. then u'll get no. of records and also this no. is the no. of last record. n = sy-dbcnt.
You should use findTopByOrderByIdDesc()
This is called named query, you can check the documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With