View previous topic :: View next topic
|
Author |
Message |
arindambanerjee
New User
Joined: 30 Jun 2007 Posts: 39 Location: India
|
|
|
|
Hi All,
Can you please suggest if the below SQL query will extract the details of the employee with 2nd highest salary from EMP table:
Select * from EMP where sal=(
(select sal from EMP having sal=max(sal) fetch first 2 rows only ordered by descending)
) fetch first 1 row only ordered by ascending;;; |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
I dont need a query to find out who is the second best payed. I am the best paid employee, so i dont care who gets less. |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
arindambanerjee wrote: |
Hi All,
Can you please suggest if the below SQL query will extract the details of the employee with 2nd highest salary from EMP table:
Select * from EMP where sal=(
(select sal from EMP having sal=max(sal) fetch first 2 rows only ordered by descending)
) fetch first 1 row only ordered by ascending;;; |
No, it won't |
|
Back to top |
|
|
Mukesh Pandey
Active User
Joined: 11 Nov 2008 Posts: 143 Location: India
|
|
|
|
Try this..
select MAX(SAL) from emp
where sal not in(select MAX(SAL) from emp)
with ur; |
|
Back to top |
|
|
|