lemutugi
lemutugi Verified Professional
August 31, 2024

Fetch random records using Spring data JPA

1 min read7
Fetch random records using Spring data JPA

There are cheap and expensive methods to achieve this goal. The following are methods to achieve this goal starting from the least efficient to the most efficient methods:

  • Using @Query 
@Query("select i from Item i order by RAND()")
public List<Item> findRandomItems();
Java

The problem with the above select statement is that your database will order all records before returning the items hence this is expensive in large  data sets

 

Login To Read Full Article

2 reactions

Programming Share
0 comments
Be the first one to share your thoughts
Promos
promos Verified Account
Sponsored
Proxy Services
Proxy Services
Learn More

like

39
lemutugi Verified Professional
May 25

Say the alert like an African Mum

lemutugi Verified Professional
May 13

Zote😂

henry_dev
April 29, 2024

Read more →

F
Fuujo
August 2, 2023

Read more →

lemutugi Verified Professional
March 4, 2023

Read more →