SQL Server select distinct latest values

后端 未结 2 2011
星月不相逢
星月不相逢 2021-02-15 00:10

I have a table that has a ton of rows (>10K). Most of the rows have duplicate role values associated with the username.

What I am tryi

2条回答
  •  忘掉有多难
    2021-02-15 00:31

    The max query didn't work because you included request_id in the grouping - try:

    select distinct uname, role, max(request_id) as request_id 
    from das_table where uname='jsmith'
    group by uname, role
    

    SQLFiddle here.

提交回复
热议问题