So I'm trying to query the stack overflow database for a question and its answers. So far I have come across two ways to do this:
SELECT questions.Id as [Post Link], questions.title, answers.body, questions.viewcount
FROM Posts answers
INNER JOIN Posts questions ON answers.parentid = questions.id
and the second way is this
SELECT * # Replace the actual fields
FROM posts
WHERE (Id = {POST_ID}) OR (ParentId = {POST_ID})
ORDER BY PostTypeId ASC, Score DESC
which approach is better and why ? is there a different way to do this ? and is there a term in sql for this parent child relationship. Any topics I could study up on how to design efficient queries on this?