from the table display the 2nd highest salary?
and also the least 2nd salay?
Answers were Sorted based on User's Feedback
Answer / soorai ganesh
SELECT 'Second Highest Salary Is ', MAX(Salary) FROM Employee WHere Salary < ( Select MAX(Salary) FROM Employee )
SELECT 'Second Least Salary Is ',MIN(Salary) FROM Employee WHere Salary > ( Select MIN(Salary) FROM Employee )
Is This Answer Correct ? | 7 Yes | 2 No |
Answer / mehul
for 2nd highest salary
select max(salary) from employee where salary<(select max
(salary) from employee )
for 2nd least salary
select min(salary) from employee where salary>(select min
(salary) from employee )
i hope that will help you
Is This Answer Correct ? | 3 Yes | 0 No |
Answer / bobby
select p.emp_id,p.name,p.salary from
(select emp_id,name,salary,dense_rank()over( order by
salary desc)maxrank,
dense_rank()over( order by salary asc)minrank from test)p
where maxrank=2 or minrank=2
Is This Answer Correct ? | 2 Yes | 0 No |
Answer / smitha
2nd Highest Salary
Select top 1 salary from (select distinct top 2 salary
from employee order by salary desc)a
order by salary
2nd Least Salary
Select top 1 salary from (select distinct top 2 salary
from employee order by salary asc)a
order by salary desc
Is This Answer Correct ? | 3 Yes | 2 No |
Answer / sridhar sahoo
select distinct top 1 salary from payroll..emp where salary
in(select distinct top 3 salary from payroll..emp order by
salary desc)
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / prasanthi
Query for Getting 2nd least salary (replace 2 with any
number so that you will get any least salary:
select max(Salary) from Employee
where Salary in
(select distinct top 2 Salary from dbo.Employee order by
Salary asc)
Query for Getting 2nd Height salary (replace 2 with any
number so that you will get any least salary:
select min(Salary) from Employee
where Salary in
(select distinct top 2 Salary from dbo.Employee order by
Employee desc)
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / sridhar sahoo
select distinct top 1 salary from payroll..emp where salary
in(select distinct top N salary from payroll..emp order by
salary desc)
if u want top 2 put 2 at the pacece of N
if u want top 5 put 5 at the pacece of N
if u want ..............................
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / narayana
select top 1 sal from (
select top 2 sal from Emp order by sal desc) as a order by sal asc
select top 1 sal from(
select top 2 sal from Emp order by sal ) ss order by sal desc
Is This Answer Correct ? | 0 Yes | 0 No |
What is recursion? Is it possible for a stored procedure to call itself or recursive stored procedure? How many levels of sp nesting are possible?
How to rebuild indexes with alter index ... Rebuild?
What is resource db in sql server?
Explain what are the different index configurations a table can have?
What is normalization in Database ?
How to loop through the result set with @@fetch_status?
How do you find value of first column before inserting value into the second column in the same table for checking that second column must have different value than first column.
When columns are added to existing tables, what do they initially contain?
What is a filestream?
How ssrs maintain security?
What is use of attribute hierarchy ordered ? : sql server analysis services, ssas
What are approximate numeric data types in ms sql server?