Friday, September 11, 2015

Top 20 Sql server Interview questions with answer on Select statement

Sql server Select statement Interview question and answers

I have created a table name EMPLOYEE_INFORMATION.

EMPLOYEE_ID
int
EMPLOYEE_NAME
varchar(50)
EMPLOYEE_SALARY
int
EMPLOYEE_DEPARTMENT
varchar(50)

Table contain the below mention data as in snapshot: 



To Display all the Details from EMPLOYEE_INFORMATION:
SELECT * FROM dbo.EMPLOYEE_INFORMATION

To Display the information and manage in Descending order on Salary wise:
SELECT * FROM dbo.EMPLOYEE_INFORMATION ORDER BY EMPLOYEE_SALARY DESC

To Display the information and manage in Asecnding order on Salary wise:
SELECT * FROM dbo.EMPLOYEE_INFORMATION ORDER BY EMPLOYEE_SALARY ASC

To display the Employee name and Department from Table:
SELECT EMPLOYEE_NAME,EMPLOYEE_DEPARTMENT FROM dbo.EMPLOYEE_INFORMATION

To display Total Salary being paid to all Employee:
SELECT SUM(EMPLOYEE_SALARY) FROM dbo.EMPLOYEE_INFORMATION

To display Highest Salary being Paid to in Department(HR):
SELECT MAX(EMPLOYEE_SALARY) FROM dbo.EMPLOYEE_INFORMATION WHERE EMPLOYEE_DEPARTMENT='HR'

To display Lowest Salary being Paid to in Department(HR):
SELECT MIN(EMPLOYEE_SALARY) FROM dbo.EMPLOYEE_INFORMATION WHERE EMPLOYEE_DEPARTMENT='HR'

To display the Employee Name who works in WEB DEVELOPER Department:
SELECT EMPLOYEE_NAME FROM dbo.EMPLOYEE_INFORMATION WHERE EMPLOYEE_DEPARTMENT='WEB DEVELOPER'

To Display the Employee name who not works in WEB DEVELOPER Department:
SELECT EMPLOYEE_NAME FROM dbo.EMPLOYEE_INFORMATION WHERE EMPLOYEE_DEPARTMENT NOT IN ('WEB DEVELOPER')

To find the Highest Salary of Employee:
SELECT MAX(EMPLOYEE_SALARY) FROM dbo.EMPLOYEE_INFORMATION

To find the Minimum Salary of Employee:
SELECT MIN(EMPLOYEE_SALARY) FROM dbo.EMPLOYEE_INFORMATION

To Display the Employee Name and Salary between the Range:
SELECT EMPLOYEE_NAME,EMPLOYEE_SALARY FROM dbo.EMPLOYEE_INFORMATION WHERE EMPLOYEE_SALARY BETWEEN 7000 AND 9000

To Display top 5 Records of Table:
SELECT TOP 5 EMPLOYEE_SALARY FROM dbo.EMPLOYEE_INFORMATION

To Count the number of Rows:
SELECT COUNT(*) FROM dbo.EMPLOYEE_INFORMATION

To Find the Employee Name Starts with ALPHABET ‘V’:
SELECT * FROM dbo.EMPLOYEE_INFORMATION WHERE EMPLOYEE_NAME LIKE 'v%'

To Find the Employee Name where Second ALPHABET is ‘I’:
SELECT * FROM dbo.EMPLOYEE_INFORMATION WHERE EMPLOYEE_NAME LIKE '_I%'

To Find the Employee Name End with ALPHABET ‘Y’:
SELECT * FROM dbo.EMPLOYEE_INFORMATION WHERE EMPLOYEE_NAME LIKE '%Y'

To display Employee Name whose Salary is GRETAER than ‘9000’ and work in Department ‘WEB DEVELOPER’:
SELECT EMPLOYEE_NAME FROM dbo.EMPLOYEE_INFORMATION WHERE EMPLOYEE_DEPARTMENT='WEB DEVELOPER' AND EMPLOYEE_SALARY>9000

To display Employee Name whose Salary is LESS than 9000 and work in Department ‘WEB DEVELOPER’: 
SELECT EMPLOYEE_NAME FROM dbo.EMPLOYEE_INFORMATION WHERE EMPLOYEE_DEPARTMENT='WEB DEVELOPER' AND EMPLOYEE_SALARY<9000



2 comments:

  1. To Display the information and manage in Asecnding order on Salary wise:
    SELECT * FROM dbo.EMPLOYEE_INFORMATION ORDER BY EMPLOYEE_SALARY DESC


    There should not be 'desc' in this statment

    ReplyDelete