Help with an SQL query on a single (comments) table (screenshot included)
Posted
by citrus
on Stack Overflow
See other posts from Stack Overflow
or by citrus
Published on 2010-06-03T21:43:45Z
Indexed on
2010/06/03
21:44 UTC
Read the original article
Hit count: 238
tsql
Please see 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?
© Stack Overflow or respective owner