title: How to select two rows from multiple rows of a column
body: <p>I have data like this</p>
  
  <pre><code>ID     | Race    | start | duration
  -------|---------| ------| ---------
  234    | 1010    | turtle| 100
  235    | 1010    | turtle| 101
  236    | 1010    | turtle| 99
  237    | 1010    | rabbit| 199
  238    | 1010    | rabbit| 201
  239    | 1010    | rabbit| 85
  240    | 9898    | rabbit| 185
  241    | 9898    | rabbit| 205
  242    | 9898    | rabbit| 505
  243    | 9898    | turtle| 155
  244    | 9898    | turtle| 104
  </code></pre>
  
  <p>from this I would like to select:</p>
  
  <ul>
  <li>one <code>turtle</code> and one <code>rabbit</code> from each group</li>
  <li>the one has to have the least duration in its group</li>
  </ul>
  
  <p>Example:</p>
  
  <p>Based on above data, the results should be:</p>
  
  <pre><code>ID     | Race    | start | duration
  -------|---------| ------| ---------
  236    | 1010    | turtle| 99
  239    | 1010    | rabbit| 85
  240    | 9898    | rabbit| 185
  244    | 9898    | turtle| 104
  </code></pre>
  
  <p>What I've done:</p>
  
  <pre><code>w = Window().partitionBy("race").orderBy(col("duration").desc())
  (df
    .withColumn("rn", rowNumber().over(w))
    .where(col("rn") == 1)
    .select("race", "duration")).show()
  </code></pre>
  
  <p>However, this groups the data and I'm not getting the desired results. </p>