Get the latest date from grouped MySQL data

前端 未结 7 851
一生所求
一生所求 2020-11-27 04:29

I have the following data in my database:

|NO | model | date     | 
+---+-------+----------+
|1  | bee   |2011-12-01|
|2  | bee   |2011-12-05|
|3  | bee   |2         


        
相关标签:
7条回答
  • 2020-11-27 05:15

    Using max(date) didn't solve my problem as there is no assurance that other columns will be from the same row as the max(date) is. Instead of that this one solved my problem and sorted group by in a correct order and values of other columns are from the same row as the max date is:

    SELECT model, date 
    FROM (SELECT * FROM doc ORDER BY date DESC) as sortedTable
    GROUP BY model
    
    0 讨论(0)
提交回复
热议问题