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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:50:49+00:00 2026-05-31T01:50:49+00:00

Context: I have an app that shows posts and comments on the home page.

  • 0

Context:

  • I have an app that shows posts and comments on the home page.
  • My intention is to limit the number of posts shown (ie, 10 posts) and…
  • Limit the number of comments shown per post (ie, 2 comments).
  • Show the total number of comments in the front end (ie, “read all 10 comments”)

MySQL:

(SELECT *
 FROM   (SELECT *
         FROM   post
         ORDER  BY post_timestamp DESC
         LIMIT  0, 10) AS p
        JOIN user_profiles
          ON user_id = p.post_author_id
        LEFT JOIN (SELECT *
                   FROM   data
                          JOIN pts
                            ON pts_id = pts_id_fk) AS d
          ON d.data_id = p.data_id_fk
        LEFT JOIN (SELECT *
                   FROM   comment
                          JOIN user_profiles
                            ON user_id = comment_author_id
                   ORDER  BY comment_id ASC) AS c
          ON p.post_id = c.post_id_fk))

I’ve failed to insert LIMIT and COUNT in this code to get what I want – any suggestions? – will be glad to post more info if needed.

  • 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-31T01:50:50+00:00Added an answer on May 31, 2026 at 1:50 am

    If I’m understanding you correctly you want no more than 10 posts (and 2 comments) to come back for each unique user in the returned result set.

    This is very easy in SQLServer / Oracle / Postgre using a “row_number() PARTITION BY”.

    Unfortunately there is no such function in MySql. Similar question has been asked here:
    ROW_NUMBER() in MySQL

    I’m sorry I can’t offer a more specific solution for MySql. Definitely further research “row number partition by” equivalents for MySql.

    The essence of what this does:

    You can add a set of columns that make up a unique set, say user id for example sake (this is the “partition”) A “row number” column is then added to each row that matches the partition and starts over when it changes.

    This should illustrate:

    user_id  row_number
    1        1
    1        2
    1        3
    2        1
    2        2
    

    You can then add an outer query that says: select where row_number <= 10, which can be used in your case to limit to no more than 10 posts. Using the max row_number for that user to determine the “read all 10 comments” part.

    Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Context: I have a WPF App that uses certain unmanaged DLLs in the D:\WordAutomation\MyApp_Source\Executables\MyApp
When I redirect in a post going back to the page that shows the
We have a WPF app that allows our users to download encrypted content and
I have this method in App Delegate that makes a window and content view
I have a Django app where multiple teams upload content that will be parsed.
I'm creating a WPF app and have a system tray icon with a context
I have this need to place my app in the share/send context menu so
I have a very simple dialog defined as: import android.app.AlertDialog; import android.content.Context; import android.view.LayoutInflater;
I have a Django app that uses MySQL as a backend. I'm having difficulties
I have an odd problem that is crashing my app, that I would like

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.