I have two tables like this:-
TABLE A
ITEM LOCATION CODE
A WHS QW123
B WHS QW124
C WHS QW125
TABLE B
ATR_NO ITEM CODE ATT_ID ATT_VALUE
20110101123310 A QW123 SIZE 24
20110101123310 A QW123 GRADE 2
20110101123351 B QW124 SIZE 20
20110101123351 B QW124 GRADE 3
20110101124042 C QW125 SIZE 26
20110101124042 C QW125 GRADE 4
20110101131210 A QW123 SIZE 26
20110101131210 A QW123 GRADE 1
20110101144542 C QW125 SIZE 27
20110101144542 C QW125 GRADE 1
The expected results using SQL shold look like this:-
RESULT
ITEM LOCATION CODE SIZE GRADE
A WHS QW123 26 1
B WHS QW124 20 3
C WHS QW125 27 1
How can I achieve that ?
Get the latest ATR_NO for each item, join that with table b twice to get the size and grade: