I am stuck with a scenario in mySQL :
I have 3 tables,
ClassRoll:
roll_no | name
123 | jack
456 | jill
789 | miriam
StudMarks:
name | Subject | marks
jack | math | 15
jill | science | 12
ExtraCurricularActivity:
name | activity
jill | singing
miriam| dancing
I need a query which will result : StudentSummary as
name | subject | marks | activity
jack | math | 15 | NA
jill | science | 12 | singing
miriam| NA | NA | dancing
I tried different ways using joins but i am unable to obtain a desired result.
SELECT cr.name, sm.marks, sm.subject, eca.activity FROM ClassRoll cr LEFT JOIN StudMarks sm ON sm.name = cr.name, extracurricularactivity eca WHERE eca.name = cr.name;2.SELECT cr.name, (CASE WHEN sm.name=cr.name THEN sm.marks ELSE 'NA' END ) marks, (CASE WHEN sm.name=cr.name THEN sm.subject ELSE 'NA' END ) subject, (CASE WHEN eca.name=cr.name THEN eca.activity ELSE 'NA' END ) activity FROM ClassRoll cr, StudMarks sm, extracurricularactivity eca WHERE cr.name=sm.name AND cr.name=eca.name;