Please get the 4 th maximum salary from a table without
using any sql keyword (TOP,MAX are mot allowed)

Answer Posted / pradeep

DECLARE @test TABLE(Empnm VARCHAR(10), Salary VARCHAR(10))

INSERT INTO @test (Empnm, Salary )
SELECT 'A', '200'
UNION ALL
SELECT 'B', '300'
UNION ALL
SELECT 'A', '200'
UNION ALL
SELECT 'B', '300'
UNION ALL
SELECT 'C', '400'
UNION ALL
SELECT 'C', '400'
UNION ALL
SELECT 'E', '100'
UNION ALL
SELECT 'D', '500'

SELECT * FROM @test


SELECT Empnm, Salary, (SELECT COUNT(DISTINCT(SALARY)) FROM
@test AS B WHERE A.Salary <= B.SALARY)
FROM @test AS A
GROUP BY Empnm, Salary
HAVING 4 = (SELECT COUNT(DISTINCT(SALARY)) FROM @test AS B
WHERE A.Salary <= B.SALARY)

Is This Answer Correct ?    9 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to get the definition of a view out of the sql server?

698


Does index speed up select statements?

747


Explain different types of collation sensitivity?

696


What is 3nf normalization form?

751


What is query and its types?

679






Name three of the features managed by the surface area configuration tool? : sql server security

708


What is the function of inner join?

752


what is denormalization and when would you go for it? : Sql server database administration

889


How we can compare two database data?

679


What do mean by xml datatype?

770


What is row_number () and partition by in sql server?

717


What are the different types of triggers in SQL SERVER?

716


What are locks in sql?

700


How do I debug a stored procedure in sql server?

718


List types of tables in SQL Azure?

120