title: Select unique pairs in self join
body: <p>I'm trying to write a simple query in sqlite with a self join.  I want all the pairs of IDs of the products that have the same cost, but I want unique pairs (i.e. don't list the same pair twice even in different order).
  Here's what I've got:</p>
  
  <pre><code>SELECT b1.Id, b2.Id
  FROM Basic AS b1
  LEFT JOIN Basic AS b2
  ON b1.cost = b2.cost
  WHERE b1.Id != b2.Id
  AND b1.Cost = 5;
  </code></pre>
  
  <p>So I get something like</p>
  
  <pre><code>23 | 101
  23 | 205
  24 | 103
  101 | 23 &lt;-- Duplicate!
  </code></pre>
  
  <p>I've tried different combinations of DISTINCT and GROUP BY but I still getting dupicate pairs:</p>
  
  <p>I've tried stuff like </p>
  
  <p>SELECT DISTINCT bp1.Id, bp2.Id ...</p>
  
  <p>&amp;
  ... = 5
  GROUP BY bp1.Id, bp2.Id;</p>
  
  <p>How can I get rid of duplicate pairs? Any ideas?</p>
  
  <p>I will appreciate your help!</p>