I am running the following SQL statement
SELECT
su.Id
,rp.QuestionId
,rp.AnswerId
FROM SiteUser su
JOIN Response rp ON su.Id = rp.SiteUserId
JOIN Answer an ON rp.AnswerId = an.Id
Which results in the following ouput
UserId QuestionId AnswerId
--------------------------------
1 1 1
1 2 6
2 1 2
2 2 3
3 1 2
3 2 2
I would like to achieve the below output
UserId Question1 Question2
-------------------------------
1 1 6
2 2 3
3 2 2
Can anyone help with writing the Pivot statement?
since you haven’t mentioned any RDBMS, this query below will work on almost all RDBMS.