Get top 1 row of each group

后端 未结 20 3001
余生分开走
余生分开走 2020-11-21 04:42

I have a table which I want to get the latest entry for each group. Here\'s the table:

DocumentStatusLogs Table

|ID| DocumentID | Status         


        
20条回答
  •  离开以前
    2020-11-21 05:15

    It is checked in SQLite that you can use the following simple query with GROUP BY

    SELECT MAX(DateCreated), *
    FROM DocumentStatusLogs
    GROUP BY DocumentID
    

    Here MAX help to get the maximum DateCreated FROM each group.

    But it seems that MYSQL doesn't associate *-columns with the value of max DateCreated :(

提交回复
热议问题