I got the table with the fields: id, foreign_key, created, modified
It's a table that logs the changes of a part of my program. What I want is to retrieve the latest logs grouped by the for开发者_运维百科eign key. How do I do this?
EDIT: to summarize, how do I order first before I group?
SELECT ... GROUP BY ... HAVING MAX(modified)
Uncorrelated subquery:
SELECT t.*
       , a.*
  FROM mytable t
       INNER JOIN 
           (select b.foreign_key
                   , max(b.modified) as max_modified 
              from mytable b 
           group by 1) a
       ON a.foreign_key = t.foreign_key 
      AND a.max_modified = t.modified
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论