table 1
id name class 1 ab A 2 cd A 3 ef B 4 ab B 5 cd B
table 2
name test marks ab 1 90 ab 2 70 cd 2 80 cd 3 85 ef 3 85 ef 4 60
Hi, I have 2 tables above, my question is what is the most efficient/best or simplest way to get the highest marks from table 2 for each person and join to table 1 such that returns:
id name class [highest marks] 1 ab A 90 2 cd A 85 3 ef B 85
Assuming SQL Server 2005+, using analytic/ranking/windowing functionality:
Using aggregates: