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...


how to find nth highest salary

Answers were Sorted based on User's Feedback



how to find nth highest salary..

Answer / nandkumar karlekar

Take this script and try u will get nth salary as you wish

create Table EmpTest
(
ID bigint,
Sal bigint
)
go
insert into emptest
values
(1,100)

insert into emptest
values
(2,200)

insert into emptest
values
(3,300)

insert into emptest
values
(4,400)

insert into emptest
values
(5,500)

insert into emptest
values
(6,600)
go
DECLARE @n bigint
--specify your nth salary
SET @n=3

select top 1 * from Emptest
where @n <= (select Count(*) from Emptest EE where EE.sal
>Emptest.sal)
order by sal desc

Is This Answer Correct ?    0 Yes 3 No

how to find nth highest salary..

Answer / latha k

declare @N INT
SET @N = 3
SELECT *
FROM [user] AS [user]
WHERE @N = (SELECT COUNT(DISTINCT(user1.Salary))
FROM [user] AS [user1]
WHERE user.Salary <= user1.Salary
)

Is This Answer Correct ?    0 Yes 3 No

how to find nth highest salary..

Answer / dilip

SELECT MIN(SALARY) FROM tablealies.Table_Name WHERE SALARY
IN (SELECT DISTINCT TOP N MAX(SALARY) FROM
tablealies.Table_Name ORDER BY SALARY DESC)

Is This Answer Correct ?    0 Yes 3 No

how to find nth highest salary..

Answer / premsagar12

SELECT DISTINCT(A.SAL),ENAME FROM EMP A WHERE &N=(SELECT
COUNT(DISTINCT(B.SAL )) FROM EMP B WHERE A.SAL<=B.SAL);

Is This Answer Correct ?    0 Yes 3 No

how to find nth highest salary..

Answer / dinesh

select distinct(a.salary)
from Salarydtls a
where 3= (select distinct(count(b.salary))
from salarydtls b
where a.salary<=b.salary)

ans is for third highest sal

Is This Answer Correct ?    0 Yes 3 No

how to find nth highest salary..

Answer / raman sharma

For third highest salary u can use this syntax

select min(cin) from ( select distinct cin from
cws.usertable order by cin desc ) where rownum<4

Is This Answer Correct ?    0 Yes 3 No

how to find nth highest salary..

Answer / bala

-- to find third highest salary from emp table
select empname,empsal from emp a where 3 = (select count(*)
from emp b where a.empsal <= b.empsal);

Is This Answer Correct ?    6 Yes 12 No

how to find nth highest salary..

Answer / sysdomain

'top' will fetch only top most : ie top 5 means it will
fetch first 5 rec. After fetching rec only 'order by' is
done ie sorting is done after fetching. therefore using
'top' and 'order by' alone wont get max or min value. for
that we have to use 'distinct' before 'top' along with
'order by' (which will sort
the records before fetching).

select top 1 salary from employee where salary in (select
distinct
top n salary from employee order by salary desc)

Is This Answer Correct ?    3 Yes 9 No

how to find nth highest salary..

Answer / mohd javed

BY Tested in Postgres SQL : javedcc@gmail.com

select * from tablename as aliasname where (nth)= (select
count(sal) from tablename where aliasname.sal<=sal)

Is This Answer Correct ?    8 Yes 16 No

how to find nth highest salary..

Answer / ganesh prasad

all are not working properly incase repeat salary
this one is correct

select min(deptsal) from dept where deptsal in ( select
distinct top 4 deptsal from dept order by deptsal desc)

Is This Answer Correct ?    6 Yes 14 No

Post New Answer

More SQL Server Interview Questions

What is the sql server agent?

0 Answers  


How to Check if table exists in sql server?

0 Answers  


what is the difference between table and view

1 Answers  


Does order by actually change the order of the data in the tables or does it just change the output?

0 Answers  


Difference between server.transfer and server.execute method?

2 Answers  


How efficient you are in oracle and SQL server?

0 Answers   CGI,


explain what is a schema in sql server 2005? Explain how to create a new schema in a database? : Sql server database administration

0 Answers  


What the class forname () does?

0 Answers  


Explain syntax for dropping triggers?

0 Answers  


how to get max salary with employee number by using one select query and max function ??

3 Answers   Genpact,


Explain triggers?

0 Answers  


What is use of attribute hierarchy ordered ? : sql server analysis services, ssas

0 Answers  


Categories