Extract accepted and most-voted answer of a question

0

Please login or register to vote for this query.

(click on this box to dismiss)

Gardening and Landscaping

Q&A for gardeners and landscapers

SELECT Id AS [Post Link], Body, Score
FROM (
    SELECT TOP 1 Id, Body, Score, DENSE_RANK() OVER(ORDER BY Score DESC) Rank 
    FROM (
        SELECT p.Id, p.ParentId, p.Body, p.Score
        FROM Posts p 
        WHERE p.ParentId = ##QuestionId##
    )x
    ORDER BY Rank ASC
)x

UNION
SELECT * 
FROM (
    SELECT Id, Body, Score
    FROM (
        SELECT a.Id, a.ParentId, a.Body, a.Score FROM Posts a 
        WHERE a.ParentId = ##QuestionId##
    )x
)x 
WHERE (SELECT b.AcceptedAnswerId FROM Posts b WHERE b.id = ##QuestionId##) = id

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results