top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Write a query to get max salary and second max salary in order in one query?

+1 vote
430 views
Write a query to get max salary and second max salary in order in one query?
posted May 12, 2017 by Jdk

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

SELECT * FROM (SELECT * FROM table_name ORDER BY column_name DESC ) WHERE ROWNUM <3;

let table name AJ and column name SALARY then select top to row in descending order, order by salary

SELECT * FROM (SELECT * FROM aj ORDER BY salary DESC ) WHERE ROWNUM <3;

answer Jun 30, 2017 by Ajay Kumar
0 votes

Hey, your ans is here, hope it will help, here table name is salary_table and column name is salary , based on that query is look like this...

SELECT * FROM (SELECT * FROM salary_table ORDER BY salary DESC) WHERE ROWNUM < 3;
answer Aug 7, 2019 by Siddhi Patel
Similar Questions
+1 vote

How we can get nth max salary from Employee Table (EMP_ID, Salary)

Emp_id salary
1 1000
3 2000
4 16000
2 10000
7 19000
8 12000

e.g. for 3rd max salary, salary is 12000 so answer will be emp_id : 8

+2 votes

I am a beginner. Can someone explain how to write a SOQL query to get child custom object when parent information is given and vice versa?
//student__c - child object, college__c-parent object, Related through Master detail

...