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 a list like this: [[(video1,4)], [(video2,5),(video3,8)], [(video1,5)], [(video5, 7), (video6,9)]...] each item
Imagine a list with some items. Each item is a movie and includes: the
For each item in my application's settings, I've added text to its Description Property
I want to have color indicators for each item in the list view in
My stackpanels have gaps between each item (TextBlocks). You can see through to whatever
I have lists of variable length where each item can be one of four
I have a listview and each item has a title, some info, and a
I have the data structure For each item there is a record of it's
I want to be able to separate each item in a listbox with a
I have a list, each item of which has several things in it, including

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.