SQL Server Interview Questions
Below are the list of common SQL Server Interview Questions, that generally candidate faces in their IT company Interviews.
In this blog post various aspect of the interview questions and answers are posted. I tried to cover the practical approach which sql statements the you can try and run on your database to make it more clear.
So lets have a look on these questions and answers.
How to find third or nth maximum salary from salary table
SELECT Salary,EmpName,ROW_NUMBER() OVER(ORDER BY Salary) As RowNum
) As A
WHERE A.RowNum IN (2,3)
Delete duplicate rows Sql Server
Take a look in the following table content. Its having duplicate rows.
Id Name Department
1 Deepak .NET
2 Jitendra .NET
3 Annu php
4 Deepak .NET
5 Yogesh Graphics
Row 1 and 4 are duplicate. So we have to remove one row and keep one in the table.
Now question is how to do?
WITH tblTemp as ( SELECT ROW_NUMBER() Over(PARTITION BY Name,Department ORDER BY Name) As RowNumber,* FROM <table_name> ) DELETE FROM tblTemp where RowNumber >1
Write down the query to print first letter of a Name in Upper Case and all other letter in Lower Case.(EmployDetail table)
SELECT UPPER(SUBSTRING(FirstName,1,1))+LOWER(SUBSTRING(FirstName,2,LEN(FirstName)-1)) AS [FirstName]