3

I understand the use of data Explorer to get my questions. However I can't get the accepted answers to the questions.

My query is as follows in the data explorer:

DECLARE @UserId int = ##MyAccountID##

SELECT Posts.Tags,Posts.Title,Posts.Body
FROM Posts
WHERE Posts.OwnerUserId = @UserId

How do I get the accepted answers as well?

1 Answer 1

5

Add an extra join on the posts table and join on acceptedanswerid, like so:

DECLARE @UserId int = ##MyAccountID:int?3632206##

SELECT Posts.Tags,Posts.Title,Posts.Body, acc.body [accepted answer]
FROM Posts 
left outer join posts acc on posts.acceptedanswerid = acc.id
WHERE Posts.OwnerUserId = @UserId

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .