Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Mysql select row that contains max value with conditions

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading