SQL how to find rows which have highest value of specific column

前端 未结 6 390
花落未央
花落未央 2021-01-19 23:37

For example, the table has columns MYINDEX and NAME.

MYINDEX | NAME
=================
1       | BOB
2       | BOB
3       | CHARLES

Ho do

6条回答
  •  说谎
    说谎 (楼主)
    2021-01-20 00:02

    SELECT MAX(MYINDEX) FROM table
    WHERE NAME = 'BOB'
    

    For the whole row, do:

    SELECT * FROM table
    WHERE NAME = 'BOB'
    AND MyIndex = (SELECT Max(MYINDEX) from table WHERE NAME = 'BOB')
    

提交回复
热议问题