MySql queries to find highest, second highest etc. values
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;

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;
Comments
Post a Comment