A come across the problem where I wanted to design a software like facebook. Page contains the millions of records you can say post to be displayed. It is single page application. So I found lazy loading is the best solution for this scenario. And yes my solution was reasonable from UI perspective and we started implementation. Next challenge we face is to design a database query. As we are using lazy loading we need only 30 records at a time, so normal simple sql statement will not work for sure. We were doing the webapi call each time user scroll down after certain number of records. We need only 30 records at a time and not all million records. The best approach we found after considering different aspect is to use the NTILE sql query.

SELECT NTILE(50) OVER(ORDER BY NAME) Paging,  * FROM PostData.sPost.tPost P
) AS T


Please follow and like us:
SQL Query for Millions of Row with Lazy loading using NTILE

Leave a Reply

Your email address will not be published. Required fields are marked *