Posts

Showing posts with the label MYSQL

MySql queries to find highest, second highest etc. values

Image
If we have a table 'account' with fields 'accountid' and 'balance', 1. Query to find highest balance from 'account' is:  select balance from account order by balance desc limit 0,1; 2.  Query to find second highest balance from 'account' is:    select balance from account order by balance desc limit 1,1;   3.  Query to find third highest balance from 'account' is: select balance from account order by balance desc limit 2,1;