开发者

How to get a row that has the maximum value in a column?

How to get a row that has the maximum value in a column?

This below 开发者_开发技巧works for me but I don't know if there is another cleaner way..

SELECT * FROM `moto` where (matricula = (SELECT max(matricula) FROM `moto`)) 


Nope, this is the way to go. Mind you, this will get you all the rows with that max, if there are multiple

(This query is also featured in one of my MySQL book (o'reilly). It's sort of a classic example)


You can also do SELECT * FROM moto ORDER BY matricula DESC LIMIT 1

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜