Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


Write a query to find second highest salary of an employee.

Answers were Sorted based on User's Feedback



Write a query to find second highest salary of an employee. ..

Answer / ashish

select salary from
(select dense_rank() over(order by salary desc) as highest, salary from employee)as y
where highest=2

: replace 2 with n.... it will give nth highest salary
: rank() will work correctly only if all the salaries in employee table are distinct.
: dense_rank() will work correctly, does'nt matter salaries are distinct or NOT.

Is This Answer Correct ?    1 Yes 0 No

Write a query to find second highest salary of an employee. ..

Answer / shahnawaz

please check this one .
first rank the salary coloum and then find nth heigest
salary
use rank function


select * from
(select a.*, rank()over(order by salary desc) rn from
emp_shah a)

Is This Answer Correct ?    1 Yes 0 No

Write a query to find second highest salary of an employee. ..

Answer / prashant srivastava

**Exact answer to the question**

SELECT MIN(e1.Salary) FROM emp e1 WHERE e1.Salary IN
(Select e2.Salary from emp e2 ORDER BY e2.Salary DESC FETCH
FIRST 2 ROWS ONLY)

**Generic Solution**

SELECT MIN(e1.Salary) FROM emp e1 WHERE e1.Salary IN
(Select e2.Salary from emp e2 ORDER BY e2.Salary DESC FETCH
FIRST n ROWS ONLY)

Just replace n as the asked rank of the salary. For instance

If 29th highest salary is asked then replace n with 29..
simple...isn't it? :):)

Is This Answer Correct ?    1 Yes 0 No

Write a query to find second highest salary of an employee. ..

Answer / raaghav

Try this query
===================
SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP n salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary
where n > 1 '(n is always greater than one)

E.g.:-
SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP 6 salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary

Is This Answer Correct ?    1 Yes 0 No

Write a query to find second highest salary of an employee. ..

Answer / abhishek

SELECT MAX(SALARY) FROM EMPLOYEE WHERE SALARY NOT IN (SELECT
MAX(SALARY) FROM EMPLOYEE)

Is This Answer Correct ?    1 Yes 0 No

Write a query to find second highest salary of an employee. ..

Answer / ayyappa

Select max(esal) from emp where esal < (Select max
(esal) from emp)

Is This Answer Correct ?    1 Yes 0 No

Write a query to find second highest salary of an employee. ..

Answer / jia

select * from employee orderby salary DESC
Limit 1,1

Is This Answer Correct ?    12 Yes 12 No

Write a query to find second highest salary of an employee. ..

Answer / rk

select sal from
(select rank() OVER (order by sal desc) sno ,sal from emp)
y
where sno= n

here
y : is the alias name for (select rank() OVER (order by sal
desc) sno ,sal from emp)
n : is the number ie if u want second highest sal then 'n'
value will be 2. for third highest n= 3...

Is This Answer Correct ?    5 Yes 5 No

Write a query to find second highest salary of an employee. ..

Answer / jawad humayun

SELECT MIN(salary)
FROM employ
WHERE salary IN (SELECT salary
FROM employ
ORDER BY salary DESC
LIMIT 2)

This querry will give the 2nd highest salary
to have nth highest salary replace 'LIMIT 2' by 'LIMIT n'

Is This Answer Correct ?    2 Yes 2 No

Write a query to find second highest salary of an employee. ..

Answer / barochia dharmesh

select Income from (
select Rank() over(order by Income desc) topRecord, Income
from (select distinct Income from tblName) tbl ) tbl2
where topRecord = 2

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More Automation Testing AllOther Interview Questions

What is test driven development?

0 Answers  


In realtime what is the Testing Process especially in automation plz its very urgent

1 Answers   IBM,


Plz suggest me a tool which supports ActiveX controls

3 Answers  


What are the limitations of automating software testing?

0 Answers  


hi, I want to study TIA portla V11. where can I get online courses?

0 Answers  


i am living in pune.from 2 months i am searching s/w testing class.but i am confuse which is the good.please send me reply who complete their testing course..i want where teaching is very good & give real project.because many insti.assured placement & real time project,but after addmission it will not be true.so send me reply.i also confuse where i put my query.i hope so,will get reply soon

5 Answers  


Differentiate between hdam and hidam database?

0 Answers  


What could go wrong with test automation?

1 Answers  


I am testing a GIS based application so Can anyone tell me which automation testing tool is best for this application?

0 Answers  


how to read data from a csv file using Test complete functional tool..please can anyone post the code

5 Answers  


Which test cases can be automated?

0 Answers  


Tell me which web driver implementation is the fastest?

0 Answers  


Categories