title: SQL Select only rows with Minimum Value on a Column with Where Condition
body: <p>Table:</p>
  
  <pre>
  | id | productId | orderIndex | rejected |
  ------------------------------------------
  | 1  |  1        |   0        |   1      |
  | 2  |  1        |   1        |   0      |
  | 3  |  1        |   2        |   0      |
  | 4  |  2        |   0        |   0      |
  | 5  |  2        |   1        |   1      |
  | 6  |  3        |   0        |   0      |
  </pre>
  
  <p>How can I select one row per productId with minimum orderIndex that not rejected?</p>
  
  <p>Expected result:</p>
  
  <pre>
  | id | productId | orderIndex | rejected |
  ------------------------------------------
  | 2  |  1        |   1        |   0      |
  | 4  |  2        |   0        |   0      |
  | 6  |  3        |   0        |   0      |
  </pre>
  
  <p>I tried this query, but don't recieved correct result:</p>
  
  <pre>
  SELECT id, productId, min(orderIndex)
  FROM table
  WHERE rejected = 0
  GROUP BY productId
  </pre>
  
  <p>This one don't work also:</p>
  
  <pre>
  SELECT id, productId, min(orderIndex)
  FROM (
      SELECT id, productId, orderIndex
      FROM table
      WHERE rejected = 0
  ) t
  GROUP BY productId
  </pre>