var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: group by, max and another column
Say I have the table below:
PKey ColA ColB ColC
1 a1 b1 c1
2 a1 b2 c2
3 a1 b3 c3
... a2 ...
... a3 ...
If I group by ColA with the select statement as follows:
If for example for a1 the MAX(ColB) is b2, THEN I would like to include ColC in the select statement such that for a1 the resulting row would be:
ColA ColB ColC
a1 b2 c2
What is the best way to do this?
the best way? only the optimizer has the final word
here is one way: take the query you posted, which finds the max ColB for each ColA, and join it back to the table as a subquery
note that you need to join on not only the ColAs, but also ColB to the max value of ColB
JOIN ( your query here )