jeudi 14 juillet 2016

How to combine two columns in mysql? [on hold]

It is a doubt. I have two tables one table contains student name,roll number,subject id. For example: JOHN 22 1,2 SAM 33 2,1 ROY 32 1,2 here 1,2 is my subject id. Where one belongs to subject1 and 2 belongs to subject2, both are optional for a particular student. And the second table contain subject1 and subject2 mark. I want to combine both subjects mark into one column for corresponding students: SELECT table1.roll_num,table1.student_name, CASE WHEN FIND_IN_SET(8, 'table1.subject_id') THEN sub1 ELSE sub2 END AS subject_mark FROM table2 JOIN table1 ON table1.student_id = table2.student_id WHERE division = 'A ORDER BY table1.roll_num asc

Aucun commentaire:

Enregistrer un commentaire