Hi, I've a table (R_TABLE) which is:R_PK | C_PK | NUM3794 | 1506 | 1.463794 | 1507 | 1.323795 | 1507 | 1.023795 | 1509 | 1.443795 | 1512 | 1.623796 | 1516 | 0.953796 | 1517 | 0.943796 | 1518 | 0.94
What I'd like is a way of doing a group by on R_PK to get the max NUM but also to return the corresponding C_PK with it. However, the one catch is that I could have the same NUM with two C_PKs and in this case I only want to return either one (it doesn't matter which). So in this case, the result set should be:R_PK | C_PK | MAX_NUM3794 | 1506 | 1.463795 | 1512 | 1.623796 | 1518 | 0.94
The best I could come up with wasselect R.R_PK, R.C_PK, RM.MAX_NUM from (select R_PK, MAX(NUM) MAX_NUM from R_TABLE group by R_PK) RM inner join R_TABLE R on R.R_PK = RM.R_PK and R.NUM = RM.MAX_NUM
But, obviously it doesn't work as I get duplicates in the 3794 row:R_PK | C_PK | MAX_NUM3794 | 1506 | 1.463795 | 1512 | 1.623796 | 1517 | 0.943796 | 1518 | 0.94
Heelllllppp :)Edited by - Tigerite on 06/23/2003 10:32:20Edited by - Tigerite on 06/23/2003 10:33:19