Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle SQL: Merge rows into single row

How to merge rows into single row in SQL?

ex: SELECT distinct studentID, studentName, MathGrade, SciGrade from vStudentGrade;

output:

   StudentID       studentName        MathGrade         SciGrade
    1               Zed                89
    1               Zed                                  98

desired output:

  StudentID        studentName        MatheGrade         SciGrade
   1                Zed                89                 98
like image 396
Ianthe Avatar asked Oct 26 '25 14:10

Ianthe


1 Answers

I wonder what criteria you're using to group them. I'm assuming there always be NULL values and a number... because that matches de example, but more detail would be better!

SELECT studentID, studentName, max(MathGrade), max(SciGrade) from vStudentGrade
group by studentID, studentName, MathGrade, SciGrade

Hope this helps or guide you to a solution :)

like image 139
Mosty Mostacho Avatar answered Oct 29 '25 04:10

Mosty Mostacho