Mysql join query on two tables with multiple colums but redundant many times -


i have 2 tables this:

studentanswer

stunum | quiznum | questionid | stuanswer ------------------------------------------ 2012   |    1    |     15     | optiona 2013   |    1    |     15     | optionb 2012   |    2    |     16     | optionc 2012   |    2    |     17     | optiona 2012   |    2    |     18     | optionb 

questionquiz

quiznum | questionid | question         | correctans ---------------------------------------------------- 1       |     15     | sql      | optiona 2       |     16     | web      | optionc 2       |     17     | android  | optiona 2       |     18     | math     | optionb 

i want result :

question        | correctans | stuanswer ------------------------------------- web     | optionc    | optionc android | optiona    | optiona math    | optionb    | optionb 

i want stuanswer based on stunum=2012, quiznum=2

i tried code loop 3 times

select b.stunum      , b.quiznum      , b.questionid      , c.question      , c.correctans      , c.markquiz      , b.stuanswer    studentanswer b    join questionquiz c      on b.quiznum = c.quiznum   b.stunum = 2012     , c.quiznum = 2 

this result got :

question        | correctans | stuanswer ---------------------------------------- web     | optionc    | optionc android | optiona    | optiona math    | optionb    | optionb web     | optionc    | optionc android | optiona    | optiona math    | optionb    | optionb web     | optionc    | optionc android | optiona    | optiona math    | optionb    | optionb 

you have join on quiznum , questionid.

join questionquiz c      on b.quiznum = c.quiznum ,     b.questionid = c.questionid  

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -