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 are these 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
EmpId | EmpName | ManagerId | DeptId | Salary | DOB |
---|
1 | Satish | 10 | 3 | 20,000 | 1996-04-30 |
2 | Ganesh | 6 | 2 | 30,000 | 1994-10-17 |
3 | Devansh | 0 | 1 | 45,000 | 1990-01-15 |
4 | Divakar | 0 | 2 | 47,000 | 1992-07-19 |
5 | Neeraj | 3 | 1 | 15,000 | 1995-01-31 |
6 | Naveen | 0 | 2 | 60,000 | 1989-03-31 |
department
DeptId | DeptName |
---|
1 | Finance |
2 | IT |
3 | Marketing |
incentives
EmpId | Incentives | IncentiveDate |
---|
2 | 2000 | 2016-10-17 |
4 | 10000 | 2017-01-15 |
5 | 6000 | 2017-04-30 |
1 | 5000 | 2017-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 '%[%]%'