Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 696235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:02:32+00:00 2026-05-14T03:02:32+00:00

What is a scalable way to select latest 10 items from each category. I

  • 0

What is a scalable way to select latest 10 items from each category.

I have a schema list this:

item   category   updated

so I want to select 10 last update items from each category. The current solution I can come up with is to query for categories first and then issue some sort of union query:

categories = sql.execute("select categories from categories_table")
query = ""
for cat in categories:
   query += "union select top 10 from table where category=cat order by updated"
result = sql.execute(query)

I am not sure how efficient this will be for bigger databases (1 million rows).
If there is a way to do this in one go – that would be nice.

Any help appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T03:02:33+00:00Added an answer on May 14, 2026 at 3:02 am

    This will not compile but you’ll have the general idea:

    from i in table
    group i by i.category into g
    select new { cat = g.Key, LastTens = g.OrderByDescending(o => o.Updated).Take(10).Select(...) }
    

    EDIT: the question asked for SQL:

    SELECT * FROM 
    (
        SELECT
            ROW_NUMBER() OVER (PARTITION BY categoryId ORDER BY somedate) AS PartNum,
            categoryId,
                [...]
        FROM
            category
    ) AS Partitionned
    WHERE PartNum <= 10
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for scalable way to do the following: User login Fetch all
Is there any scalable Win32 API (like IOCP not like select) that gives you
I'm working on a system than has to be pretty scalable from the beginning.
Looking for the easist/most scalable way to do a set "difference" in SQL Server
Is there a better way to do this: perms = product(range(1,7),range(1,7),range(1,7)) so that I
Erlang's Characteristics From Erlang Programming (2009): Erlang concurrency is fast and scalable. Its processes
I'm looking for a way to store files, namely images(maybe videos) in a scalable
I have a visualization web application (small project) that creates charts and graphs from
I have an asp.net-mvc website and people manage a list of projects. Based on
Is there a way how can I send data to RabbitMQ from $.ajax? My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.