title: Group the return results of mysql
body: <p>I was almost exhausted tweaking the queries and finally thought of posting the question here to get the help. I have a mysql table as below. I am coding in Nodejs and accessing the database using jdbc connector.</p>
  
  <pre><code>name    subject class   score
  Harry   science 8   60
  John    Science 9   65
  Harry   Maths   8   80
  Harry   English 9   50
  Mike    Maths   8   90
  John    English 8   60
  </code></pre>
  
  <p>When I do my query, I need to get the result "grouped by name" and "class=8". I know that I can return all the results where "class=8" and then iterate through the result`s to form the below object. As my real database is quite complex, I want return result from mysql itself to be grouped as below. Can it be possible using mysql query? If not possible using query, what is the best and safest way to code in order to get the below format?</p>
  
  <pre><code>{
  Harry:[{score:60, subject: science}, {score:80, subject: Maths}],
  John:[{score:60, subject: English}],
  Mike:[{score:90, subject: Maths}]
  }
  </code></pre>