How to select a maximum value row in mysql table

前端 未结 7 1514
感情败类
感情败类 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 07:15

    MAX is an aggregate function. That means MySQL groups all of the records and treats them as if they were one in the result set. Since you doesn't state how the name column is to be grouped, the result of that may be unexpected. ORDER BY is a perfectly fine way to achieve the desired result. Just don't forget to add an index on age so the performance isn't affected as the table grows.

    0 讨论(0)
提交回复
热议问题