title: Select Top 1 with ties with distinct on another field column
body: <p>I have a sample table record like this:</p>
  
  <pre><code>AutoID  ReceiptNo  Outlet_Code  
  -------------------------------- 
      1       SUN12        Store X     
      3       SUN12        Store X     
      4       ART123       Store y
  </code></pre>
  
  <p>I would like to select a top 1 with ties based on Outlet_Code with Distinct on the ReceiptNo such that in this case, my result will be:</p>
  
  <p><strong>Store X / Store Y</strong></p>
  
  <p>because I should read the 2 Store X records as 1 as they have the same receiptNo.</p>
  
  <p>This is a portion of my query:</p>
  
  <pre><code>SELECT TOP 1 WITH TIES (Outlet_Code)                  
  From [Trans] T                 
  WHERE T.CardNo IN (Select [CardNo] From [Card]                
                           Where  [MemberID] = 
                           (Select [ID] From [Member]  Where [autoid] = @MemAutoID ))   
  GROUP BY Outlet_Code     
  ORDER BY Count(T.Outlet_Code) Desc 
  </code></pre>