I want to do Data Analysis on some Stack Overflow Posts and need to get a query output in the right format. My goal is to input Post ID's and get my answers in the following format:
ID|Title|Question|Answer1|Answer2|Answer3|Answer4|Answer5|Answer...
__________________________________________________________________
1 |Tit 1|Quest 1 |1.Answ |2.Answ |3.Answ |4.Answ |5.Answ |Answer...
2 |Tit 2|Quest 2 |1.Answ |2.Answ |3.Answ | | |
3 |Tit 3|Quest 3 |1.Answ |2.Answ |3.Answ |4.Answ | |
I am not familiar with writing queries on StackExchange but i managed to write a query to get almost the right output. My results is like this:
ID|Title|Question|Answer|
_________________________
1 |Tit 1|Quest 1 |1.Answ |
1 |Tit 1|Quest 1 |2.Answ |
1 |Tit 1|Quest 1 |3.Answ |
2 |Tit 2|Quest 2 |2.Answ |
2 |Tit 2|Quest 2 |2.Answ |
2 |Tit 2|Quest 2 |2.Answ |
As you can see i duplicate the Id,Title and Question for each answer. And the answers are in a column and not side by side. This is the query i managed to write. Can somebody help me with that or point me in the right direction?
select
p.Id, p.Title, p.Body, k.Body
from
Posts as p inner join
Posts as k on
p.id = k.parentid
where
p.Id in (##id##) and k.posttypeid=2