title: SQL For-each Loop Alternative
body: <p>I have two tables (let's call them TradingWindows and VolumeData).  Each row of TradingWindows has a startBin and endBin for each different stock.  In VolumeData, there are columns stock,binIndex,volume.</p>
  
  <p>I want to combine this information by doing the following operation:  for-each row in the TradingWindows table I want to sum up the all the volume binIndex's that are > startBin and &lt; endBin.  (the idea is to get the total volume between start and end).</p>
  
  <p>Now, coming from a procedural programming background this is easy (just write a for-each loop).  I know this is possible in SQL, but I am new and was wondering if there is a more efficient way to do it.</p>
  
  <p>Thanks!</p>