Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

For example, the table has columns MYINDEX and NAME.

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

Ho do I find row with highest MYINDEX for specific NAME? E.g. I want to find ROW-2 for name "BOB".

like image 671
SharpAffair Avatar asked Dec 02 '22 05:12

SharpAffair


1 Answers

SELECT Max(MYINDEX) FROM table WHERE NAME = [insertNameHere]

EDIT: to get the whole row:

Select * //never do this really
From Table
Where MYINDEX = (Select Max(MYINDEX) From Table Where Name = [InsertNameHere]
like image 80
AllenG Avatar answered Dec 04 '22 01:12

AllenG