I'm working with a sample table like below. A Dataset has multiple groups, and each time a write to the table occurs, the RunNumber increments for the dataset, along with data for each group and the total. Each Dataset/Group combo will usually have multiple rows, example below:
| RunNumber | Group | Dataset | Total |
|---|---|---|---|
| 1 | Group1 | Dataset A | 10 |
| 1 | Group1 | Dataset A | 20 |
| 2 | Group1 | Dataset A | 30 |
| 2 | Group2 | Dataset A | 15 |
| 1 | Group1 | Dataset B | 5 |
| 1 | Group2 | Dataset B | 10 |
| 1 | Group3 | Dataset A | 30 |
| 2 | Group3 | Dataset A | 30 |
| 1 | Group1 | Dataset C | 15 |
| 1 | Group2 | Dataset C | 50 |
| 2 | Group2 | Dataset C | 70 |
| 2 | Group2 | Dataset C | 90 |
What I want to do is essential for each combination of Dataset and Group, return all data for rows that have the max(RunNumber) for the given Dataset/Group combination. So for example, the above sample would return this:
| RunNumber | Group | Dataset | Total |
|---|---|---|---|
| 2 | Group1 | Dataset A | 30 |
| 2 | Group2 | Dataset A | 15 |
| 1 | Group1 | Dataset B | 5 |
| 1 | Group2 | Dataset B | 10 |
| 2 | Group3 | Dataset A | 30 |
| 1 | Group1 | Dataset C | 15 |
| 2 | Group2 | Dataset C | 70 |
| 2 | Group2 | Dataset C | 90 |
Where the Dataset/Groups match, all rows are kept with the max RunNumber for that given combo. For now, I've split this into 2 separate queries, where i first query for the max(RunNumber) for all distinct Dataset/Group combos, then do a select * for all matches. Any help would be appreciated, thanks in advance!