By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,404 Members | 1,937 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,404 IT Pros & Developers. It's quick & easy.

Top Value in a Table

P: 12
Hi all

I need to get a 2'nd top Salary from the table Employee. I don't know how to write a query for this in postgresql. Could you please help me out to write.

I tried in MSSQL. It is working fine.
select top 3 salary from employee

But it is not working in Postgre. What is the equivalent for Top in postgre.

Thanks
Kavitha
Sep 19 '07 #1
Share this Question
Share on Google+
3 Replies


amitpatel66
Expert 100+
P: 2,367
Hi all

I need to get a 2'nd top Salary from the table Employee. I don't know how to write a query for this in postgresql. Could you please help me out to write.

I tried in MSSQL. It is working fine.
select top 3 salary from employee

But it is not working in Postgre. What is the equivalent for Top in postgre.

Thanks
Kavitha
Try below Query to get second highest salary from the table:

Expand|Select|Wrap|Line Numbers
  1. SELECT MIN(e.salary) FROM emp e WHERE 2 > (SELECT COUNT(*) FROM emp WHERE salary > e.salary)
  2.  
Sep 19 '07 #2

Expert 100+
P: 700
or like that

select salary from (select distinct salary from emp group by salary order by salary) t order by t.salary limit 1 offset 1;
Sep 19 '07 #3

P: 12
thank you for your fast reply. It is working fine..
Sep 20 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.