lemutugi
lemutugi Verified Professional
August 31, 2024

Fetch random records using Spring data JPA

1 min read233 views
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
eastearn Verified Organization
Sponsored
Looking to expand your reach?
Advertise your products and services on our platform and connect with a wider audience of businesses and professionals.
Advertise With Us!
lemutugi Verified Professional
May 25

Say the alert like an African Mum

eastearn Verified Organization
Sponsored
Looking to expand your reach?
Advertise your products and services on our platform and connect with a wider audience of businesses and professionals.
lemutugi Verified Professional
May 13

Zote😂

henry_dev
April 29, 2024

Read more →

F
Fuujo
August 2, 2023

Read more →

mystore Verified Organization
Sponsored
Shop from Multiple Stores in Various Locations
Discover a wide range of products from multiple stores across different locations. Shop conveniently with MyStore and find the best deals near you!
lemutugi Verified Professional
March 4, 2023

Read more →