This question already has answers here:
How can I SELECT rows with MAX(Column value), DISTINCT by another column in SQL?
                                
                                    (18个回答)
                                
                        
                                2年前关闭。
            
                    
我使用一个名为Page的表的mysql数据库。有什么办法只能从每个页面中提取最新版本吗?

ID      Page Title      Version
0001    Homepage        1
0002    Homepage        2
0003    Homepage        3
0004    Contact         1
0005    Contact         2
0006    Basket          1
0007    Basket          2
0008    Basket          3
0009    Basket          4


我需要的:

ID      Page Title      Version
0003    Homepage        3
0005    Contact         2
0009    Basket          4

最佳答案

您可以使用MAXGROUP BY,如下所示:

 SELECT MAX(ID)
        ,PageTtile
        ,MAX(version)
    FROM Page
    GROUP BY PageTitle

08-25 12:12