how to find nth highest salary
Answers were Sorted based on User's Feedback
Answer / sameera chiluka
select secondMAXsal from emp
WHERE seconMAXsal = ((MAXsal)-1);
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / amarjit singh
--display 3rd higest salary in MSSQLSERVER
select max(sal) from emp
where sal <(select max(sal) from emp
where sal <(select max(sal) from emp
))
--By , STUDENT OF IET BHADDAL ENG COLLEGE
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / balindra sahani
select max(salary) from table_name where max(salary)not
in(select top(n) from table_name order by salary asc)
where n=nth number salary
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / mangalesh porwal
HERE N IS THE NO WHICH HIGHEST NO U WANT..........
IT SURELY WORKS.....
SELECT TOP 1 * FROM (SELECT TOP N * FROM (SELECT ROLLNO FROM TABLE_NM ) AS D ORDER BY ROLLNO DESC) AS P ORDER BY ROLLNO
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / p rem satyam
This is perfect
...............................
select * from emp e1 where (N-1)=( select
count(distinct(e2.sal) from emp e2 where e2.sal > e1.sal)
where N is level of sal. suppose you want 3rd higest sal then
in place u write 3 i.e write (3-1).
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / venuprasadh
SELECT MIN(SALARY) AS Salary FROM user WHERE SALARY IN
(SELECT DISTINCT TOP 3 SALARY FROM user ORDER BY SALARY DESC);
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / ravikiran
select * from employee.e1 where (n-1) =
( select (distinct b.salary ) from employee.e2 where e1.salary > e2.salary
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / amit kumar
--- Getting 4th highest salary
--- 4 can be replaced with any number
with EmpSal as
(Select *, row_number() over (order by EmpSal Desc)
as 'rownumber' from employee)
Select * from EmpSal where rownumber =4
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / neeraj kumar
select top(1) salary from(
select distinct nth salary
from emp
order by salary desc)a
order by salary
In this answer you can put any position in place of nth then you find the salary.
If you are satisfied this answer then reply me please.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / jeevan
CREATE TABLE
[dbo].[Table_1]([ID] [int] NOT NULL,[SAL] [int] NULL)
//N=9
SELECT TOP 1 * FROM dbo.Table_1
WHERE ID NOT IN (SELECT TOP 8/*N-1*/ ID FROM dbo.Table_1
ORDER BY SAL DESC)
ORDER BY SAL DESC
| Is This Answer Correct ? | 0 Yes | 0 No |
What is onf in normalization form?
How will oyu test the stored procedure taking two parameters namely first name and last name returning full name?
What is the difference between varchar and varchar(max) datatypes?
Define ACID properties in a Database?
Explain magic tables in sql server?
How to resolve the orphan use problem? : sql server security
Is trigger fired implicitely?
What is row_number () and partition by in sql server?
How to connect php with different port numbers?
Explain a checkpoint?
I have a table Events Events containing cardno,time,id,name--each id has a cardno my requirement is every day each employee swipe the card several times i want to calculate first and last time of each card the output should be name 1 2 6 7 in out in out holiday holiday xxx 09:30 06:30 09:40 06:45 where 1,2...... are dates for example january 1,2, etc. 6 and 7 are saturday and sunday how it is posssible
Which event (check constraints, foreign key, rule, trigger, primary key check) will be performed last for an integrity check?
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)