title: Selecting only distinct rows based on a column in Knex
body: <p>I'm using <a href="http://knexjs.org/" rel="nofollow noreferrer">Knex</a>, a pretty nice SQL builder.</p>
  
  <p>I've got a table called <code>Foo</code> which has 3 columns</p>
  
  <pre><code>+--------------+-----------------+
  | id           | PK              |
  +--------------+-----------------+
  | idFoo        | FK (not unique) |
  +--------------+-----------------+
  | serialNumber | Number          |
  +--------------+-----------------+
  </code></pre>
  
  <p>I'd like to select all rows with <code>idFoo IN (1, 2, 3)</code>. </p>
  
  <p>However I'd like to avoid duplicate records based on the same <code>idFoo</code>. </p>
  
  <p>Since that column is not unique there could be many rows with the same <code>idFoo</code>.</p>
  
  <h3>A possible solution</h3>
  
  <p>My query above will of course return all with <code>idFoo IN (1, 2, 3)</code>, even duplicates.</p>
  
  <pre><code>db.select(
    "id",
    "idFoo",
    "age"
  )
  .from("foo")
  .whereIn("idFoo", [1, 2, 3])
  </code></pre>
  
  <p>However this will return results with duplicated <code>idFoo</code>'s like so:</p>
  
  <pre><code>+----+-------+--------------+
  | id | idFoo | serialNumber |
  +----+-------+--------------+
  | 1  | 2     | 56454        |
  +----+-------+--------------+
  | 2  | 3     | 75757        |
  +----+-------+--------------+
  | 3  | 3     | 00909        |
  +----+-------+--------------+
  | 4  | 1     | 64421        |
  +----+-------+--------------+
  </code></pre>
  
  <p>What I need is this:</p>
  
  <pre><code>+----+-------+--------------+
  | id | idFoo | serialNumber |
  +----+-------+--------------+
  | 1  | 2     | 56454        |
  +----+-------+--------------+
  | 3  | 3     | 00909        |
  +----+-------+--------------+
  | 4  | 1     | 64421        |
  +----+-------+--------------+
  </code></pre>
  
  <p>I can take the result and use Javascript to filter out the duplicates. I'd specifically like to avoid that and write this in Knex.</p>
  
  <p>The question is how can I do this with Knex code? </p>
  
  <p>I know it can be done with plain SQL (perhaps something using <code>GROUP BY</code>) but I'd specifically like to achieve this in "pure" knex without using raw SQL.</p>