I have a situation like this:
name, age
Tom, 30
Tom, 30
Sam, 35
Sam, 34
...
I would like to remove duplicated id, but if their value (in this case age has different values) I would like to keep the max. So my output should be like this: name, age
Tom, 30
Sam, 35
Obviously, SELECT DISTINCT won't work. Any suggestion, on how to handle this situation? Thank you!
CodePudding user response:
You want to aggregate the data with the same name and, in particular, you are searching for the max, then you can use the corrispondent aggregation function
select name, max(age) from table group by 1