title: MySQL selecting more than one id depending on value
body: <p>I'm working on stock control in my system and i have a table for "locations" of stock in a warehouse. This is the location table.</p>
  
  <pre><code>id  location_description_id location_key    product_id  qty
  6   1                       1               3           25
  7   1                       2               4           25
  8   1                       3               3           20
  </code></pre>
  
  <p>I'm struggling with getting the location values. For example if there is an order for 40 pieces for product id "3", you can see there is 25 pieces in location_key 1 and 20 pieces in location_key 3</p>
  
  <p>What would be the best way to select the next available location_key when the first one runs out? so in this case the return would be id 6, qty 25 and id 8, qty 15 (totaling my 40)</p>