Say I have a table with 3 cols: ActionId, uid & created.
I want to group actions by the uid, but every time a new action is inserted into a group (by uid), it will push the group upto the top, and individual rows within that group ordered.
This is what I came up with in SQL:
select * from actions as a
inner join
(
select aa.[uid], MAX(aa.[created]) as maxcreated
from actions as aa
group by aa.[uid]
) as a2 on a2.uid = a.uid
order by a2.maxcreated desc, a.created desc
Is there a better way to achieve this in SQL, and also then how to do this in LINQ?
So you want each group ordered internally, and the groups order by the latest value, right? Okay, I think we can do that…