can anybody tell us, how to select 2nd max salary from
table.
my id is ashish.akk@gmail.com
Answers were Sorted based on User's Feedback
Answer / dileep.t
If you need the second highest salary only
then following will also work,
select Max(Salary) from TableName
where Salary not in(
Select Max(Salary) from TableName)
| Is This Answer Correct ? | 20 Yes | 3 No |
Answer / preeti chauhan
CREATE TABLE T1(SALARY int, [NAME] varchar(50))
SELECT TOP 1 SALARY FROM (SELECT TOP 2 SALARY FROM T1 ORDER
BY SALARY DESC)T1 ORDER BY SALARY
| Is This Answer Correct ? | 15 Yes | 3 No |
Answer / kumar_kisna
select max(salary) from table where salary<(select max
(salary) from table)
| Is This Answer Correct ? | 4 Yes | 1 No |
Answer / divya
select max(sal) from tablename where sal<(select
max(sal)from tablename)
| Is This Answer Correct ? | 3 Yes | 0 No |
Answer / arun kumar ks
In the case more than one highest SALARY, only the Dilip’s
answer is correct.
| Is This Answer Correct ? | 3 Yes | 1 No |
Answer / sabin v jacob
SELECT Min(Sal) FROM (SELECT TOP 2 Sal FROM emp ORDER BY
Sal desc) as Temp
or
SELECT Min(Sal) FROM emp WHERE Sal IN(SELECT TOP 2 Sal FROM
emp ORDER BY Sal DESC)
| Is This Answer Correct ? | 5 Yes | 3 No |
Answer / rajendra
Select Top 1 * From Tablename where salary in
(select top 2 salary from tablename order by salary desc)
order by salary asc
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / neeru
I think Daleep answer is not so precise, if you want 3rd or
ny specified answer, this only can only be seems right for
2nd highest salary, else, its not optimise query.I found
Preeti's query more optimistic and accurate.
| Is This Answer Correct ? | 1 Yes | 0 No |
In SQL Server 2000 Query:
-------------------------
select max(salary) from Employee where salary not in(select
max(salary) from employee)
This Query only selects the 2'nd Higehest Salary in that
table. So, you will try...
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / harikumar
select max(salary) as secondMax from employee where id <>
(select max(salary) from employee)
| Is This Answer Correct ? | 1 Yes | 0 No |
Do you know what is a with(nolock)?
what information is maintained within the msdb database? : Sql server administration
When would you use an insert into .. Select option versus an insert into .. Values option? Give an example of each?
Explain the use of containers in ssis and also their types?
Can a table be created inside a trigger?
How to delete duplicate records from a table?(for suppose in a table we have 1000 Records in that we have 200 duplicate Records , so ,how to findout that duplicate Records , how to delete those Records and arranged into sequence order? one more thing that there is no primary key at all)
What is the purpose of update statistics and scope_identity() function?
Explain about system stored procedure?
Tell me the phases a transaction has to undergo?
What is 'Join' and explain its various types.
What are number line correlation administrators will use while working with a subquery?
What is difference in performance between insert top (n) into table and using top with insert?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)