title: Self Join without duplicates
body: <p>I have a table that represents possible connections between stations of a public transport service. It looks like this:</p>
  
  <pre><code>trip_id | station_id | sequence
  --------+------------+---------
    1     |   A        |   1
    1     |   B        |   2
    1     |   C        |   3
    2     |   C        |   1
    2     |   B        |   2
    2     |   A        |   3
  </code></pre>
  
  <p>Now I want to select all possible connections between two stations without duplicates, i. e. I just need the connection A->B and not B->A.</p>
  
  <p>I came up with this Join but unfortunately there are duplicates:</p>
  
  <pre><code>SELECT DISTINCT c1.station_id, c2.sation_id 
  FROM connections c1, connections c2 
  WHERE c1.trip_id = c2.trip_id AND c1.sequence = c2.sequence-1
  </code></pre>