title: Set-based alternative to loops in SQL
body: <p>I read many posts saying in SQL you should think in terms of sets and not in terms of loops. I am trying to do the following: </p>
  
  <pre><code>SELECT SUM(Score)
  FROM (SELECT W.StemId, W.Weight*Q.Weight As Score
      FROM TfidfWeights AS W
      INNER JOIN Query AS Q ON W.StemId = Q.StemId
      WHERE W.DocumentId = '0054f88e-a565-4f54-866a-e6107948567e') TMP
  </code></pre>
  
  <p>How do I achieve to obtain 'Score' for every 'DocumentId' I have. In other words avoid looping through the 'Documents' table and compute the 'Score' for each document.</p>