Table:
| id | productId | orderIndex | rejected | ------------------------------------------ | 1 | 1 | 0 | 1 | | 2 | 1 | 1
http://sqlfiddle.com/#!9/0196f/2
SELECT DISTINCT t.* FROM table1 t INNER JOIN ( SELECT productId, min(orderIndex) minIdx FROM table1 WHERE rejected = 0 GROUP BY productId ) t1 ON t.productId = t1.productId AND t.orderIndex = t1.minIdx;