ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
 
Categories  >>  Software  >>  Databases  >>  SQL Server
 
 


 

 
 Oracle interview questions  Oracle Interview Questions
 SQL Server interview questions  SQL Server Interview Questions
 MS Access interview questions  MS Access Interview Questions
 MySQL interview questions  MySQL Interview Questions
 Postgre interview questions  Postgre Interview Questions
 Sybase interview questions  Sybase Interview Questions
 DB Architecture interview questions  DB Architecture Interview Questions
 DB Administration interview questions  DB Administration Interview Questions
 DB Development interview questions  DB Development Interview Questions
 SQL PLSQL interview questions  SQL PLSQL Interview Questions
 Databases AllOther interview questions  Databases AllOther Interview Questions
Question
Please get the 4 th maximum salary from a table without 
using any sql keyword (TOP,MAX are mot allowed)
 Question Submitted By :: Ayanb1302@yahoo.com
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Please get the 4 th maximum salary from a table without using any sql keyword (TOP,MAX are mot allowed)
Answer
# 1
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 ?    1 Yes 1 No
Pradeep
 
  Re: Please get the 4 th maximum salary from a table without using any sql keyword (TOP,MAX are mot allowed)
Answer
# 2
Create Table 'Employee' with columns 'Emp_Name' 
and 'Salary'. And, Insert some data.....

Cursor:
declare Cursor_Name cursor scroll
for select salary from Emploee order by salary desc
open Cursor_Name
fetch absolute 2 from Cursor_Name
deallocate Cursor_Name
 
Is This Answer Correct ?    0 Yes 0 No
Sumathy
 
 
 
  Re: Please get the 4 th maximum salary from a table without using any sql keyword (TOP,MAX are mot allowed)
Answer
# 3
Am Sumathy the above answer was posted by me.

For the above Answer 'absolute 2' will fetch 2nd maximum 
value.

To fetch 4th maximum value use 'absolute 4'
To fetch 'n'th maximum value use 'absolute n'
 
Is This Answer Correct ?    0 Yes 0 No
Sumathy
 
  Re: Please get the 4 th maximum salary from a table without using any sql keyword (TOP,MAX are mot allowed)
Answer
# 4
select payout,emp_cd from empmas e where 2>(select count(payout) from empmas s where s.payout>e.payout);
 
Is This Answer Correct ?    0 Yes 0 No
Suresh
 
  Re: Please get the 4 th maximum salary from a table without using any sql keyword (TOP,MAX are mot allowed)
Answer
# 5
select * from (select *,row_number()over (order by salary
asc)as a from Employee)as b where b.a=4
 
Is This Answer Correct ?    0 Yes 0 No
Gajendra
 

 
 
 
Other SQL Server Interview Questions
 
  Question Asked @ Answers
 
logshipping is Any difference 2000 and 2005?  1
What is the purpose of using COLLATE in a query?  1
How do we rollback the table data in SQL Server  3
Can we call SP inside a query? Wipro4
How to write query to Delete the records in child table and corresponding records in parent table Semantic-Space8
When do you use SQL Profiler?  2
What types of integrity are enforced by a foreign-key constraint  1
If there exist a index on the table, and we then make a view on that table (include the indexed column from base table) than why do we require indexing on view?Doesnt it create an overhead?  1
What is the difference between Drop and Truncate  10
How to delete particular value in the column of a table.Is it possible or not?if possible give it as in query.  4
Rate yourself in .NET and SQL ? Cognizent1
How to Get the last identity value used  4
Differences between functions and stored procedures? 247Customer6
what is the order of execution of where,having,group by in select stement Tanla-Solutions5
What is a deadlock and what is a live lock? How will you go about resolving deadlocks? Microsoft1
What are the authentication modes in SQL Server?  2
How many types of cursors are there in SQL Server? 247Customer3
How to Display, Amount of Disk Activity Generated by Transact-SQL Statements?  1
What are primary keys and foreign keys?  3
Explain Trigger with an example?  1
 
For more SQL Server Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com