I am trying to join 2 tables, but only join with the latest record in a group of records.
The left table:
Part
- Part.PartNum
The right table:
Material
- Material.Partnum
- Material.Formula
- Material.RevisionNum
The revision number starts at “A” and increases.
I would like to join the 2 tables by PartNum, but only join with the latest record from right table. I have seen other examples on SO but an having a hard time putting it all together.
Edit:
I found out the first revision number is “New”, then it increments A,B,… It will never be more than one or two revisions, so I am not worried about going over the sequence. But how do I choose the latest one with ‘New’ being the first revision number?
A general SQL statement that would run this would be:
Repeating the above caveats about what happens after Revision #26. The max(RevisionNum) may break depending upon what happens after #26.
EDIT:
If RevisionNum sequence always starts w/ NEW and then continues, A, B, C, etc., then the max() needs to be replaced w/ something more complicated (and messy):
There must be a better way to do this. This works though — will have to think about a faster solution.
SQL Fiddle: http://sqlfiddle.com/#!3/70c19/3