mysql - Left join for three tables -


i have 3 tables follows

table - user answerd

 user id    |   question id |   answer option id    |    1        |           1   |               2       |    1        |           2   |               1       | 

table b - question

question id | question text     | 1           | question 1        | 2           | question 2        | 

table c - answer

answer id   |   question id |   answer option id    |answer text                | 1           |   1           |                   1   |question 1 answer 1        | 2           |   1           |                   2   |question 1  answer 2       | 2           |   2           |                   1   |question 2 answer 1        | 3           |   2           |                   2   |question 2  answer 2       | 

i want find out user gave answer result should this

    1       |   question 1  |   question 1 answer 2     |     1       |   question 2  |   question 2 answer 1     | 

i tried so

select * left join b on a.question_id = b.question_id left join c on a.answer_option_id = c.answer_option_id 

can here me?

you missing ensuring last join gets answers right question.

try this:

select *  left join b on a.question_id = b.question_id left join c on a.answer_option_id = c.answer_option_id , a.question_id = c.question_id 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -