title: mysql complex request by distinct pair (non commutative)
body: <p>I'm trying to create an sql (mariadb) request that select multiples columns but need two columns to be a unique pair but making sure the pair selected has its created_at value the least than the other duplicata pairs.</p>
  <p>Here is what my table approximately looks like :</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>id</th>
  <th>from_user_id</th>
  <th>to_user_id</th>
  <th>created_at</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>1</td>
  <td>2</td>
  <td>1000000005</td>
  </tr>
  <tr>
  <td>2</td>
  <td>2</td>
  <td>1</td>
  <td>1000000002</td>
  </tr>
  <tr>
  <td>3</td>
  <td>2</td>
  <td>3</td>
  <td>1000000008</td>
  </tr>
  <tr>
  <td>4</td>
  <td>5</td>
  <td>6</td>
  <td>999999999</td>
  </tr>
  <tr>
  <td>5</td>
  <td>6</td>
  <td>5</td>
  <td>100000006</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I made this table precise to explain the request I want.</p>
  <p>So I want to select the distinct pair (from_user_id, to_user_id) implying that the couple (1,2) which could also be (2,1) should be unique. The second rule is it should pick the couple with the minimum created_at value.</p>
  <p>So the result table I want is :</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>id</th>
  <th>from_user_id</th>
  <th>to_user_id</th>
  <th>created_at</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>2</td>
  <td>2</td>
  <td>1</td>
  <td>1000000002</td>
  </tr>
  <tr>
  <td>3</td>
  <td>2</td>
  <td>3</td>
  <td>1000000008</td>
  </tr>
  <tr>
  <td>4</td>
  <td>5</td>
  <td>6</td>
  <td>999999999</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>2,1,1000000002 because the created_at is lesser than the other same couple case (1,2,1000000005).</p>
  <p>In this case if I want only the values above created_at:999999999 to be selected I just have to add one condition.</p>
  <p>I really hope my question is clear. I'm struggling to make distinct pairs work with other columns.</p>
  <p>Thanks in advance for your answers.</p>