Home > front end >  Mysql select row that contains max value with conditions
Mysql select row that contains max value with conditions

Time:01-01

I would like to select the row that caontains the max value on a column (rank) with specific conditions : 1 : result > 0 2 : apply = 17

enter image description here

this is my sql select

SELECT *
FROM mytable
WHERE apply = 17 and result > 0
HAVING MAX(rank)

In this exapmle i should have as output the row with id 11

CodePudding user response:

You are not aggregating here so having is not correct; you want a single row based on an order (by rank) so

SELECT *
FROM mytable
WHERE apply = 17 and result > 0
ORDER BY rank DESC
LIMIT 1;
  • Related