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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:46:19+00:00 2026-06-11T15:46:19+00:00

Here is my table arrangement: Posts post_id post_votes Comments comment_id post_id comment_time I have

  • 0

Here is my table arrangement:

Posts
   post_id
   post_votes

Comments
   comment_id
   post_id
   comment_time

I have failed to create a query that does the following:

  1. Select 10 Posts Order By post_votes desc
  2. While getting 5 comments for each post

I will post what I have tried if necessary.
I am just getting into more complicated queries, any help or suggestions is greatly 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-06-11T15:46:21+00:00Added an answer on June 11, 2026 at 3:46 pm

    The below will retrieve 10 post order by desc and also 5 comments order by desc respectively.

    select post_id,post_votes,comment_id,comment_time,
     @rn := CASE WHEN @prev_post_id = post_id THEN @rn + 1 ELSE 1 END AS rn,
            @prev_post_id := post_id from
      (select p.post_id,post_votes,comment_id,comment_time from
      (SELECT post_id,post_votes from posts order by post_votes desc limit 10) p 
       left outer join 
       comments c on p.post_id=c.post_id order by post_id,comment_time desc )m
    having rn<=5
    

    SQL FIDDLE HERE (testing sample of retrieving 3 post order by desc and also 2 comments for each post respectively).

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

Sidebar

Related Questions

I have a query that selects all the information from a database table and
I have a simple self referencing table as depicted here: CREATE TABLE [dbo].[Project]( [ProjectId]
Lets say we have a table here, populated with the following data: acc_id1 acc_id2
http://logging.apache.org/log4net/release/config-examples.html Given the log table here: CREATE TABLE [dbo].[Log] ( [Id] [int] IDENTITY (1,
I got an oracle db 10g, here a table as an example create table
I have a nested table arrangement for displaying data. I want the nested table
I have here sample table with three fields. TableA FieldA FieldB FieldC ====================================== 123XYZ456
Im not sure what is wrong with my create table here. Keeps giving me
Consider we have a database that has a table, which is a record of
here display-table does not work in ie7. is there any way apply the same

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.