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 533991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:33:56+00:00 2026-05-13T09:33:56+00:00

Each item in c_data is in a category/section. I would like to limit how

  • 0

Each item in c_data is in a category/section. I would like to limit how many items are displayed per category, rather than limiting the total number of items retrieved. Obviously if I add something like “limit 20” to the query, it will only fetch 20 results in total, rather than 20 results per category.

   SELECT cm.id,
                cm.title AS cmtitle,
                cm.sectionid,
                cm.type AS cmtype,
                cd.id,
                cd.time,
                cd.link,
                cd.title,
                cd.description,
                cd.sectionid AS sectionid
      FROM c_main AS cm
      JOIN c_data AS cd ON cd.sectionid=cm.sectionid
     WHERE cd.sectionid=cm.sectionid 
     ORDER by id ASC

The field with the category is “sectionid”.

  • 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-13T09:33:56+00:00Added an answer on May 13, 2026 at 9:33 am

    MySQL doesn’t have any ranking functionality, but you can use a variable to create a psuedo row number.

    Use:

    SELECT x.*
      FROM (SELECT cm.id,
                   cm.title AS cmtitle,
                   cm.sectionid,
                   cm.type AS cmtype,
                   cd.id AS cd_id,
                   cd.time,
                   cd.link,
                   cd.title,
                   cd.description,
                   cd.sectionid AS cd_sectionid,
                   CASE
                     WHEN @sectionid != cm.sectionid THEN @rownum := 1 
                     ELSE @rownum := @rownum + 1
                   END AS rank,
                   @sectionid := cm.sectionid
              FROM C_MAIN cm,
                   C_DATA cd,
                   (SELECT @rownum := 0, @sectionid := NULL) r
             WHERE cm.sectionid = cd.sectionid
          ORDER BY cm.sectionid) x
     WHERE x.rank <= 20
    ORDER BY id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have many items inside a list control. I want each item to have
Each of my clients can have many todo items and every todo item has
I've got a sections table, and an items table. The problem is each item
Each item in a WPF ListBox control seems to have a bit of left
I have a list, each item of which has several things in it, including
I've got a nice little class built that acts as a cache. Each item
I would like to compare two collections (in C#), but I'm not sure of
(please excuse that I didn't use aliases). I would like my query output to
Each time a python file is imported that contains a large quantity of static
Each year at Thanksgiving, my family has drawn names out of a hat to

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.