I want to get the top 1 row for each unique value of b with the minimum value of c for that particular value of b. Even though there may be more than 1 row with the same minimum value (just select the first one)
MYTABLE
- whole (unique)
- b integer
- c integer
I tried this request
SELECT t1.*
FROM myTable t1,
(SELECT b,
MIN(c) as c
FROM myTable
GROUP BY b) t2
WHERE t1.b = t2.b
AND t1.c = t2.c
However, in this table, there may be more than one instance of the minimum value of c for a given value of b. The above query generates duplicates in these conditions.
I have a feeling that I need to use rownum somewhere, but I'm not quite sure where.
source
share