groupwise-maximum

Select only newest records from table and make this FAST, how?

Good day, I have a question I'm struggling with a lot, hope somebody already found a clever solution to this (I use MySQL). I have table like this: Table `log` ---------- id inserted message user_id My goal is to select last inserted record for user and make this fast. Log table is huge (around 900k records), so my first approach was...

select rows with largest value of variable within a group in r

a.2<-sample(1:10,100,replace=T) b.2<-sample(1:100,100,replace=T) a.3<-data.frame(a.2,b.2) r<-sapply(split(a.3,a.2),function(x) which.max(x$b.2)) a.3[r,] returns the list index, not the index for the entire data.frame Im trying to return the largest value of b.2 for each subgroup of a.2. How can I do this efficiently? ...