title: Select distinct tuples in mysql
body: <p>I'm having a hard time reasoning about a problem:</p>
  
  <p>Given this table:</p>
  
  <pre>
  +------+------------+
  | id   | sibling_id |
  +------+------------+
  |    1 |       NULL |
  |    2 |          3 |
  |    3 |          2 |
  |    4 |          5 |
  |    5 |          4 |
  +------+------------+
  </pre>
  
  <p>If I choose <code>ids</code> <code>(1,2,3,5)</code>, I'd like to only get <code>(1,2,4)</code>, because <code>3 points to 2</code>, and <code>2 points to 3</code>, so I only want one of both.</p>
  
  <p>Expected output:</p>
  
  <pre>
  +------+------------+
  | id   | sibling_id |
  +------+------------+
  |    1 |       NULL |
  |    2 |          3 |
  |    4 |          5 |
  +------+------------+
  </pre>
  
  <p>How could I do that with mysql (5.7) ?</p>
  
  <p><strong>Solution</strong> :</p>
  
  <p><code>select distinct least(id, coalesce(sibling, id)) from test where id in (1,2,3,5);</code></p>
  
  <p>Thanks everyone !</p>