Say
Employe table contains
emp_id, salary, rank, dept_id as columns and has some data in it.
1. To get max salary from Employee table.
SELECT MAX(salary) FROM employee;
2. To get max salary from Employee table with respect to dept.
SELECT MAX(slary), dept_id from employee group by dept_id;
3. To get top 5 salary
select distinct salary from employee order by salary desc limit 5;
4. To get top 5 salary with respect to dept
select distinct salary, dept_id from employee order by salary desc limit 5;
5. To get 2nd max salary
select max(salary) from employee where salary not in(select max(salary) from employee);
5. To get 2nd max salary with respect to department
select max(salary), dept_id from employee where salary not in(select max(salary) from employee) group by dept_id;
Hope, this will give better idea on queries to get max number and with respect to other field.
Suppose if you have rank in column and would like you to find rank, then make sure use MIN in place of MAX.
Cheers....