title: Calculating the SUM of (Quantity*Price) from 2 different tables
body: <p>I have two tables as follows</p>
  
  <p><code>PRODUCT</code> table</p>
  
  <pre><code>Id | Name | Price
  </code></pre>
  
  <p>And an <code>ORDERITEM</code> table</p>
  
  <pre><code>Id | OrderId | ProductId | Quantity
  </code></pre>
  
  <p>What I'm trying to do is, calculate the subtotal price for each product (Quantity*Price) then SUM the TOTAL value for the entire order..</p>
  
  <p>I'm trying something like this</p>
  
  <pre><code>SELECT Id, SUM(Quantity * (select Price from Product where Id = Id)) as qty
  FROM OrderItem o
  WHERE OrderId = @OrderId
  </code></pre>
  
  <p>But of course that doesn't work :)</p>
  
  <p>Any help appreciated!</p>
  
  <p><strong>EDIT:</strong> I only want to show the grand total for the entire order, so basically the sum of Quantity*Price for every row in OrderItem. Here's some sample data.</p>
  
  <p><strong><em>Sample Data</em></strong></p>
  
  <p><strong>TABLE Product</strong></p>
  
  <pre><code>Id     Name            Price  
  1      Tomatoes        20.09    
  4      Cucumbers       27.72    
  5      Oranges         21.13    
  6      Lemons          20.05
  7      Apples          12.05
  </code></pre>
  
  <p><strong>Table OrderItem</strong></p>
  
  <pre><code>Id         OrderId        ProductId        Quantity
  151        883            1                22
  152        883            4                11
  153        883            5                8
  154        883            6                62
  </code></pre>
  
  <p>M</p>