I'm studying the tables that are provided by the Data Explorer for Stack Overflow. In the table Post there is a column called AcceptedAnswerID, but there is not an AcceptedAnswer table. So where is the answer stored when a user replies to a question?


1 Answer 1


Since the Posts table contains entries for both questions and answers (distinguished by their Posts.PostTypeId), to get the accepted answer for the current question you'll have to perform a JOIN on Posts.AcceptedAnswerId and Posts.Id, setting Posts.PostTypeId = 2 to get posts of type Answer.

Below is the query to retrieve the answer count and the id of the accepted answer in raw data form, for the post with the given id:

SELECT Posts.AnswerCount, Posts.AcceptedAnswerId
FROM Posts
  Posts.Id = 19628880;

You can find the whole query, forkable and modifyable, on Data Explorer here.

  • Thanks for your answer i have upvote your answer and mark as correct . Thanks again
    – A.Goutam
    Commented Jun 1, 2015 at 12:15
  • @A.Goutam See my edit for the query and the link on DataExchange.
    – JoErNanO
    Commented Jun 1, 2015 at 12:25

You must log in to answer this question.

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