SQLTeam.com | Weblogs | Forums

Get the Max number for each group


#1

I am not sure how to word it correctly, so I will just give you an example.

I need a way to get the max id for each group. Most of them are two rows with same SSN, but different ID. I want to be able to get a list of those with higher ID for each group. ID is a PK field. SSN is a social security field and some of then are in it more than once.

Current Result

ID | SSN
05 | 4044
20 | 4044
84 | 5231
44 | 5231

Desired Results. This is what I need my result to show.

ID | SSN
20 | 4044
84 | 5231


#2
select max(id), ssn 
from mytable
group by ssn

#3

Wow. That simple. Thank you. I will try it.


#4

Easy when you know how ... until then its hard :smile: