top of page
Search
Writer's pictureLeonard Anghel

How To Efficiently Finding Top N Rows Of Every Group

Updated: May 10, 2020

Motivation:

You search for an efficient approach that finds top N rows of every group.


Note:

If you are not familiar with the ROW_NUMBER() window function then consider reading How to efficiently assign a database temporary sequence of values to rows before continuing.


Description:

This application is an example of finding top N rows of every group via the ROW_NUMBER() window function.


Key points:

Write a native query relying on ROW_NUMBER() window function as in the code below:

Testing time:

Tam Ta Da Dam! :) The complete application is available on GitHub.


If you need a deep dive into the performance recipes exposed in this repository then I am sure that you will love my book "Spring Boot Persistence Best Practices".


380 views0 comments

Recent Posts

See All

How To Bulk Updates

Motivation: This article is useful if you need a fast way to update a significant amount of data in the database. Bulk operations...

Comments


bottom of page