top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

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

+1 vote
87 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

1 Answer

+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
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

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...