How to select a maximum value row in mysql table

前端 未结 7 1603
感情败类
感情败类 2020-12-15 06:30

I have the following table

Table structure:

CREATE TABLE IF NOT EXISTS `people` ( 
`name` varchar(10) NOT NULL, 
`age` smallint(5) u         


        
7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-15 06:57

    There is an interesting alternative that works only on MySql!

    SELECT `Name`, `Age` FROM 
    (SELECT `Name`, `Age`, 1 AS `foo`
    FROM `People`
    ORDER BY `Age` DESC) AS `x`
    GROUP BY `foo`
    

    This works because MySql returns the first row, when no aggregation function is applied on a given column

    Here is the link: http://tominology.blogspot.com.br/2014/10/sql-row-with-max-value.html

提交回复
热议问题