title: MySQL: Simple subquery
body: <p>I'm new to a bit more advanced MySQL and would like to learn how to do things properly with queries like the following.  </p>
  
  <p>I have two tables: sensors and measurement_data<br>
  Each sensor row has an id and each measurement_data row links to one of those sensor ids.  </p>
  
  <p>What I need to do is get sensors<br>
  (SELECT id FROM sensors)<br>
  and then get last 5 measurement_data rows for each sensor<br>
  (SELECT val FROM measurement_data WHERE sensor_id = <em>sensor id</em> ORDER BY timestamp DESC LIMIT 5)  </p>
  
  <p>The result should look something like following json:</p>
  
  <pre><code>{
       "SENSOR01": [
           "10","11","12","13","14"
       ],
       "SENSOR02": [
           "10","11","12","13","14"
       ]
  }
  </code></pre>
  
  <p>I tried to look at some examples google found for me, but they all were either too complex or at least I didn't get them.<br>
  I also tried to play with subqueries based on documentation, but did not understand how to do this.<br>
  Could someone help me get on right tracks with this?  </p>
  
  <p>Cheers</p>