title: SQL subquery and aggregate function
body: <p>I am just learning about SQL subqueries, and I am a little confused as to why this isn't working. I have two tables, Order and OrderDetails. They both have an OrderID, and the OrderDetails has the fields OrderDetails.ProductID and OrderDetails.Quantity. So different orders can have different products, and on the OrderDetails table, there can be multiple rows for an OrderID if the Order has more than one different product. </p>
  
  <p>so on the Orders Table it could be like </p>
  
  <p><strong>OrderID</strong></p>
  
  <p>10248</p>
  
  <p>10249</p>
  
  <p>10250</p>
  
  <p>and in the OrderDetails Table:</p>
  
  <p><strong>OrderID  |  ProductID  |  Quantity</strong></p>
  
  <p>10248    |      11     |    12</p>
  
  <p>10248    |      42     |    10</p>
  
  <p>10248    |      72     |    5</p>
  
  <p>etc</p>
  
  <p>What I want to do is print out a list of all OrderIDs that have more than 1 product ordered. </p>
  
  <p>I thought the following made sense:</p>
  
  <pre><code>Select Orders.OrderID 
     FROM Orders 
       WHERE Orders.OrderID = (Select OrderDetails.OrderID
                                    FROM OrderDetails
                                    GROUP BY OrderDetails.OrderID
                                    HAVING (COUNT(OrderDetails.ProductID) &gt; 1))
  </code></pre>
  
  <p>But this is certainly not working. Only one order ID is printed even though basically ever OrderID in the database has multiple products. I hope the way I asked this wasn't too confusing, it's my first time posting about SQL on here </p>