I Have Employee table having column name as ID,SALARY
how to get second max salary from employee table with id
ex
ID SALARY
1 20000
7 37000
2 5000
Answers were Sorted based on User's Feedback
Answer / belson gnana pradeep
Select Top 1 salary from (Select TOP 2 salary from tbl_salary order by salary desc)a order by salary
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / ankit nanda
select [Salary],ID from (select [Salary], ROW_NUMBER() over
(order by Employee.SALARY desc)RowNum from [Employee])e
where e.RowNum=2
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / sudip mondal
select top 1 from employee where ID in (select top2 ID from
employee order by Salary desc) order by Salary asc
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / radhakrishnan vaithilingam
SELECT TOP 1 id.salary
FROM (SELECT TOP 2 id,salary
FROM employee
ORDER BY salary DESC )a
ORDER BY a.salary ASC
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / bennison terry
Select Top 1 * from Tbl_Salary where ID not in (Select top 1 ID from tbl_salary order by salary desc) order by Id desc
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / ankit nanda
Do onething
just create a function which use the three input parameters
and
while select * from ComputeEmployee(,,,)insert one of the
designation or salary or department at a time or wtever u
want....here i used some case statement to solve the
problem..wheeeeww...one thing else uniqueidentifier i just
use for the column type,u can use a simple int also ::))
create function ComputeEmployee(@Designation nvarchar
(100),@Department nvarchar(100),@Salary bigint)
returns @DemoTable table (EmployeeID
uniqueidentifier,Designation Nvarchar(100),Name Nvarchar
(100),Department Nvarchar(100),Salary bigint)
as
begin
insert into @DemoTable
select
ed.EmployeeID,ed.Designation,ed.Name,sd.Department,sd.Salary
from EmployeeDetails ed inner join
SalaryDetails sd on sd.SalaryID=ed.EmployeeID
where ed.Designation like case when
@Designation IS not null then '%'+@Designation+'%' end
AND sd.Department like case when
@Department IS not null then '%'+@Department+'%' end
AND sd.Salary =case when @Salary Is not
null then @Salary else sd.Salary end
return
end
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / bhagya
select * from emp as e1 where 1= (select count(*)from emp
as e2 where e1.sal<e2.sal)
Is This Answer Correct ? | 9 Yes | 11 No |
You have a stored procedure, which execute a lengthy batch job. This stored procedure is called from a trigger you do not want to slow the data entry process you do not want trigger to wait for this batch job to finish before it completes itself what you can do to speed up the process?
what is the Enterprise manager(2000) and management studio (2005)?
How to view existing indexes on an given table using sp_help?
Anyone please explain me the concept of Serialization?
Differentiate between ms sql server reporting services vs crystal reports?
Explain what stored procedure sp_replcounters is used for? : sql server replication
Once setting replication, can you have distributor on sql server 2005, publisher of sql server 2008?
What is the use of custom fields in report?
Difference between DELETE and TRUNCATE?
WHAT IS UNIQUE IDENTIFIER DATA TYPE?
9. Write a query to list a new column with the difference in temp of the cities Delhi and Mumbai, Mumbai and Jammu and soon. Consider the following table : City_id City Temp. 1 delhi 40 2 Mumbai 35 3 Jammu 32 4 Pune 18
What is normalization process?