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

  • Home
  • SEARCH
  • 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 818831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:12:39+00:00 2026-05-15T02:12:39+00:00

Please see screenshot: Goal: id like to have comments nested 1 level deep The

  • 0

Please see screenshot:

screenshot

Goal:

  • id like to have comments nested 1 level deep
  • The comments would be arranged so that rating of the parent is in descending order
  • the rating of the children comments is irrelevant

The left hand side of the screenshot shows the output that Id like. The RHS shows the table data. All of the comments are held in 1 table.

Im a beginner with SQL queries, the best I can do is:

SELECT * 
FROM [Comments] 
WHERE ([ArticleId] = @ArticleId) ORDER BY [ThreadId] DESC, [DateMade] 

This somewhat does the job, but it obviously neglects the rating. So the above statement would show output where Bobs Comment and all of the children comments are before Amy’s and her childrens comments.
How can I run this query correctly?

  • 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-15T02:12:39+00:00Added an answer on May 15, 2026 at 2:12 am
    SELECT c.* 
    FROM Comments AS c
    JOIN Comments AS tr ON tr.threadID = c.threadID 
     AND tr.ArticleId = c.ArticleId AND tr.isParent = 1
    WHERE (c.ArticleId = @ArticleId) 
    ORDER BY tr.Rating DESC, c.ThreadId DESC, c.DateMade 
    

    You have to join the table with itself to get the parents rating
    then you sort by the thread rating first, then by thread id in case many threads have the same rating, and then by comment date.

    You dont have to shove int sorting by c.isParent DESC before date cause this is the oldest comment in the thread.

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

Sidebar

Related Questions

I have an Adorner which adornes a Border (please see screenshot below). The MouseDown
Please see the screenshot. I am trying to produce a layout that allows me
Please see below: I tried using Absolute layout, but that's deprecated. I appreciate your
Please see the screenshot, and advise how to remove the text in red color
Please take a look at the screenshot below and see if you can tell
[URL removed per my bosses request] - please see screenshot in first comment to
My custom view does not display entirely. Please see my screenshot: And the source
I need to code a grid for search. Please see the screenshot. When user
Here is the link for the app. Please see screenshot of first tab. As
Please see the attached screenshot which illustrates a TToolBar from one of my programs:

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.