title: Is it possible to use a single query to achieve related purchase history?
body: <p>My table consists of all order history like this:</p>
  
  <pre><code>table: orderhistory
  
  OrderID       ProductID       CustomerID        Quantity        
       1                   4                       1                        1
       1                   5                       1                        2
       1                   6                       1                        1
       2                   4                       2                        1
       2                   3                       2                        1
       2                   5                       2                        1
  </code></pre>
  
  <p>OrderID and ProductID are primary keys.<br>
  So purchase history related to product 4 consists of product 3, 5 and 6. And product 5 should be prior to other records as it appears twice together with 4 in a single order. How can I use a single query to grab that information?</p>
  
  <p>Desired result: (query for related history of product 4)</p>
  
  <pre><code>ProductID       Freq       
       5                   2
       6                   1
       3                   1
  </code></pre>