Few interview sql queries [Resolved]

Posted by Rajendra.prasad under Sql Server on 5/4/2011 | Points: 10 | Views : 5333 | Status : [Member] | Replies : 1
Hi All,

1. query for displaying top 2 highest salary emp details
2. query for displaying emp details where dept having more than 1 employee
3. query for displaying emp details where more than 1 employee stay in same location

Regards,
Rajendra




Responses

Posted by: Ndebata on: 5/4/2011 [Member] Starter | Points: 50

Up
0
Down

Resolved
1. query for displaying top 2 highest salary emp details

SELECT EmployeeName,Salary from
(SELECT *,DENSE_RANK() over( order by Salary desc) SRANK from Employee) as Emp
Where SRANK = 2

details can be found on your previous post. :)
http://www.dotnetfunda.com/forums/thread4523-how-to-select-top-2-salary-and-name-from-employee-table.aspx
2. query for displaying emp details where dept having more than 1 employee

SELECT * from Employee Where Department IN
(
Select Department from Employee
Group by Department Having Count(1)> 1
)

3. query for displaying emp details where more than 1 employee stay in same location

SELECT * from Employee Where Location IN
(
Select location from Employee
Group by location Having Count(1)> 1
)


Thanks,
Debata


Rajendra.prasad, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response