SQL Query Interview Questions and Answers

SQL Query in SQL Server interview questions

These SQL Query in SQL Server questions have been designed for various interviews, competitive exams and entrance tests. We have covered questions on both basic and advanced concepts which will help you improve your skills to face interview questions on SQL Query.

Who is this SQL Query interview questions designed for?

All the experienced programmer, database administrator, database developers, DBA, tester, web developers, application developers, programmers and software engineer will find these questions extremely useful. All freshers, BCA, BE, BTech, MCA and college students wanting to make a career in front end designing will be highly benefited by these questions.

SQL Query interview questions topics

This section covers SQL Query in SQL Server topics like - RDBMS Concepts, Data Types, Operators, Create Database,Drop Database,Select Database,Create Table, Drop Table, Order By, Group By, Constraints, Joins, Unions, Indexes, Views, Date Functions etc.
SQL Query interview questions and answers are based on following tables: Employee, Department and Incentives

employee

EmpIdEmpNameManagerIdDeptIdSalaryDOB
1Satish10320,0001996-04-30
2Ganesh6230,0001994-10-17
3Devansh0145,0001990-01-15
4Divakar0247,0001992-07-19
5Neeraj3115,0001995-01-31
6Naveen0260,0001989-03-31

department

DeptIdDeptName
1Finance
2IT
3Marketing

incentives

EmpIdIncentivesIncentiveDate
220002016-10-17
4100002017-01-15
560002017-04-30
150002017-07-19

1. Write a SQL query to get random employee record from the table.

Answer:

select top 1 * from employee order by newid()

2. Write a SQL query to select first 2 characters of EmpName from employee table.

Answer:

select substring(EmpName,1,2) from employee

3. Write a SQL query to get length of EmpName from employee table.

Answer:

select len(EmpName) from employee

4. Write a SQL query get employee details from employee table whose employee name are "Neeraj" and "Naveen".

Answer:

Select * from employee where EmpName in ('Neeraj','Naveen')

5. Can you select employee details from employee table whose name ends with 'h' and name contains 5 letters?

Answer:

Select * from employee where EmpName like '_____n'

6. Write a SQL query to get position of 'a' in name 'Naveen' from employee table.

Answer:

Select CHARINDEX('a',EmpName,0) from employee where EmpName='Naveen'

7. Select all EmpName after removing white spaces from right side.

Answer:

select RTRIM(EmpName) from employee

8. Select names of employees who has '%' in EmpName.

Answer:

Select EmpName from employee where EmpName like '%[%]%'