I'm trying to join all of the fields from two tables based on an account ID. The account ID is unique in table 1, but is repeated in table 2. In table 2, I only want to pull in one record per ID.
Table 1:
ID...Field1....Field2
1......aa.........bb
2......cc.........dd
3......ee.........ff
4......gg.........hh
Table 2:
ID...Field3....Field4......Field5
1.....123........123...........123
1.....345........546...........453
2.....123........123...........123
3.....123........123...........123
4.....123........123...........722
4.....123........123...........333
4.....123........123...........123
I need to select which ID to pull in from table 2 based on their values in three fields. The logic works like this. Among the duplicates, pick the ID record that has the highest value in field3, if they're all the same, pick the one with the highest value in field4, if they're still the same, pick the one with the highest value in field5.
So that the end result looks like this:
ID....Field1.....Field2.....Field3.....5ield4.....Field5
1........aa..........bb............345.......546.........452
2........cc..........dd............123.......123.........123
3........ee..........ff............123.......123.........123
4........gg..........hh............123.......123.........722
Thank you so much! This one has stumped me for a while now