We have put together list of practice SQL Queries for Interview. Before you start practicing these SQL Queries, use the provided code to Create required Database tables. Fell free to modify these queries to find alternate methods to get the same answers. Use our forum to post questions related to Database programming and one of our admins or registered users will reply back to your query.

All these practice SQL Queries have been tested successfully on Microsoft SQL Server 2014 and Microsoft SQL Server 2017. You would need to run the provided script code in New Query Window, within Microsoft SQL Server Management Studio to Create the Database and Require tables. Under the Code Create Sample Data Section, I have provided the Script Code to create sample data for all tables. Run the this code after you have created the required tables.

Practice these Frequently Asked SQL Queries once before your Interview to get ready to perform them in front of the interviewer.  Please Like, Share and Comment my work to motivate me to produce  more stuff for you guys.

CODE TO CREATE DATABASE AND TABLES

CREATE DATABASE [Practice_SQL]

Create Table [dbo].[Department] (
[Department_ID] [int] Not Null,
[Name] [nvarchar] (50) Not null,
[Location] [nvarchar] (50) Not Null
)

Create Table [dbo].[Employee] (
[Employee_ID] [int] Not Null,
[Employee_Name] [nvarchar] (50) Not null,
[Job] [nvarchar] (50) Not Null,
[Manager_ID] [int] Null,
[Hiredate] [Date] Not Null,
[Salary] [int] Not Null,
[Commission] [int] Null,
[Department_ID] [int] Not Null
)

CODE TO CREATE SAMPLE DATA

INSERT [dbo].[Department] ([Department_ID], [Name], [Location]) VALUES (10, N’ACCOUNTING’, N’NEW YORK’)

INSERT [dbo].[Department] ([Department_ID], [Name], [Location]) VALUES (20, N’FINANCE’, N’DALLAS’)

INSERT [dbo].[Department] ([Department_ID], [Name], [Location]) VALUES (30, N’SALES’, N’SEATTLE’)

INSERT [dbo].[Department] ([Department_ID], [Name], [Location]) VALUES (40, N’OPERATIONS’, N’CHICAGO’)

INSERT [dbo].[Department] ([Department_ID], [Name], [Location]) VALUES (1, N’HEADQUARTERS’, N’BERLIN’)

INSERT [dbo].[Employee] ([Employee_ID], [Employee_Name], [Job], [Manager_ID], [Hiredate], [Salary], [Commission], [Department_ID]) VALUES (6369, ‘MILLER’, ‘CLERK’, 6682, CAST(‘2000-01-17’ AS Date), 25000, 1550, 10)

INSERT [dbo].[Employee] ([Employee_ID], [Employee_Name], [Job], [Manager_ID], [Hiredate], [Salary], [Commission], [Department_ID]) VALUES (6499, ‘FORD’, ‘SENIOR ANALYST’, 6698, CAST(‘1999-10-25’ AS Date), 60000, 2000, 20)

INSERT [dbo].[Employee] ([Employee_ID], [Employee_Name], [Job], [Manager_ID], [Hiredate], [Salary], [Commission], [Department_ID]) VALUES (6500, ‘WINSTO’, ‘MANAGER’, NULL, CAST(‘2001-01-20’ AS Date), 50000, 2000, 30)

INSERT [dbo].[Employee] ([Employee_ID], [Employee_Name], [Job], [Manager_ID], [Hiredate], [Salary], [Commission], [Department_ID]) VALUES (6501, ‘MARK’, ‘SALESMA’, 6968, CAST(‘1980-05-17’ AS Date), 30000, 2000, 40)

INSERT [dbo].[Employee] ([Employee_ID], [Employee_Name], [Job], [Manager_ID], [Hiredate], [Salary], [Commission], [Department_ID]) VALUES (6502, ‘RAUL’, ‘MANAGER’, 7839, CAST(‘1993-06-18’ AS Date), 50000, 2000, 30)

INSERT [dbo].[Employee] ([Employee_ID], [Employee_Name], [Job], [Manager_ID], [Hiredate], [Salary], [Commission], [Department_ID]) VALUES (6503, ‘STEVE’, ‘SALESMA’, 6968, CAST(‘2015-02-28’ AS Date), 30000, 2000, 20)

INSERT [dbo].[Employee] ([Employee_ID], [Employee_Name], [Job], [Manager_ID], [Hiredate], [Salary], [Commission], [Department_ID]) VALUES (6504, ‘KERRY’, ‘MANAGER’, 7902, CAST(‘1981-02-22’ AS Date), 50000, 2000, 30)

INSERT [dbo].[Employee] ([Employee_ID], [Employee_Name], [Job], [Manager_ID], [Hiredate], [Salary], [Commission], [Department_ID]) VALUES (6505, ‘SONIA’, ‘MANAGER’, 7839, CAST(‘1981-08-21’ AS Date), 50000, 2000, 30)

INSERT [dbo].[Employee] ([Employee_ID], [Employee_Name], [Job], [Manager_ID], [Hiredate], [Salary], [Commission], [Department_ID]) VALUES (6506, ‘JAMAL’, ‘CLERK’, 6902, CAST(‘1993-01-17’ AS Date), 25000, 2000, 20)

INSERT [dbo].[Employee] ([Employee_ID], [Employee_Name], [Job], [Manager_ID], [Hiredate], [Salary], [Commission], [Department_ID]) VALUES (6507, ‘HIZA’, ‘CLERK’, 6902, CAST(‘1997-04-22’ AS Date), 25000, 2000, 40)

INSERT [dbo].[Employee] ([Employee_ID], [Employee_Name], [Job], [Manager_ID], [Hiredate], [Salary], [Commission], [Department_ID]) VALUES (6508, ‘ROYSTO’, ‘CLERK’, 6682, CAST(‘2007-06-30’ AS Date), 25000, 2000, 40)

INSERT [dbo].[Employee] ([Employee_ID], [Employee_Name], [Job], [Manager_ID], [Hiredate], [Salary], [Commission], [Department_ID]) VALUES (6509, ‘KEVI’, ‘PRESIDENT’, 1111, CAST(‘2005-01-21’ AS Date), 500000, 2000, 1)

INSERT [dbo].[Employee] ([Employee_ID], [Employee_Name], [Job], [Manager_ID], [Hiredate], [Salary], [Commission], [Department_ID]) VALUES (6510, ‘TURNER’, ‘VICE PRESIDENT’, 1111, CAST(‘2009-03-10’ AS Date), 200000, 2000, 1)

INSERT [dbo].[Employee] ([Employee_ID], [Employee_Name], [Job], [Manager_ID], [Hiredate], [Salary], [Commission], [Department_ID]) VALUES (6511, ‘ADAMS’, ‘CEO’, 1111, CAST(‘2011-02-15’ AS Date), 1000000, 2000, 1)

INSERT [dbo].[Employee] ([Employee_ID], [Employee_Name], [Job], [Manager_ID], [Hiredate], [Salary], [Commission], [Department_ID]) VALUES (6512, ‘BLAKES’, ‘JUNIOR ANALYST’, 6699, CAST(‘2008-02-20’ AS Date), 30000, 2000, 20)

INSERT [dbo].[Employee] ([Employee_ID], [Employee_Name], [Job], [Manager_ID], [Hiredate], [Salary], [Commission], [Department_ID]) VALUES (6513, ‘JONES’, ‘IT CONSULTANT’, 6566, CAST(‘1998-11-26’ AS Date), 35000, 2000, 30)

INSERT [dbo].[Employee] ([Employee_ID], [Employee_Name], [Job], [Manager_ID], [Hiredate], [Salary], [Commission], [Department_ID]) VALUES (6514, ‘MARSHALL’, ‘JUNIOR ANALYST’, 6699, CAST(‘2000-10-25’ AS Date), 38000, 2000, 40)

INSERT [dbo].[Employee] ([Employee_ID], [Employee_Name], [Job], [Manager_ID], [Hiredate], [Salary], [Commission], [Department_ID]) VALUES (6515, ‘LAURA’, ‘IT CONSULTANT’, 6566, CAST(‘2001-07-20’ AS Date), 59000, 2000, 30)

INSERT [dbo].[Employee] ([Employee_ID], [Employee_Name], [Job], [Manager_ID], [Hiredate], [Salary], [Commission], [Department_ID]) VALUES (6516, ‘WARD’, ‘JUNIOR ANALYST’, 6698, CAST(‘2005-03-15’ AS Date), 30000, 2000, 20)

INSERT [dbo].[Employee] ([Employee_ID], [Employee_Name], [Job], [Manager_ID], [Hiredate], [Salary], [Commission], [Department_ID]) VALUES (6517, ‘COUTLER’, ‘SENIOR ANALYST’, 6721, CAST(‘2006-05-18’ AS Date), 65000, 2000, 40)

INSERT [dbo].[Employee] ([Employee_ID], [Employee_Name], [Job], [Manager_ID], [Hiredate], [Salary], [Commission], [Department_ID]) VALUES (6518, ‘LOPES’, ‘SENIOR ANALYST’, 6722, CAST(‘2001-09-13’ AS Date), 75000, 2000, 30)

INSERT [dbo].[Employee] ([Employee_ID], [Employee_Name], [Job], [Manager_ID], [Hiredate], [Salary], [Commission], [Department_ID]) VALUES (6519, ‘RALPH’, ‘SENIOR ANALYST’, 6725, CAST(‘2004-10-07’ AS Date), 65000, 2000, 20)

INSERT [dbo].[Employee] ([Employee_ID], [Employee_Name], [Job], [Manager_ID], [Hiredate], [Salary], [Commission], [Department_ID]) VALUES (6520, ‘ROZA’, ‘SENIOR ANALYST’, 6698, CAST(‘1982-11-09’ AS Date), 90000, 2000, 40)

INSERT [dbo].[Employee] ([Employee_ID], [Employee_Name], [Job], [Manager_ID], [Hiredate], [Salary], [Commission], [Department_ID]) VALUES (6521, ‘RONNIE’, ‘BUSINESS CONSULTANT’, 6566, CAST(‘1994-03-02’ AS Date), 55000, 2000, 20)

INSERT [dbo].[Employee] ([Employee_ID], [Employee_Name], [Job], [Manager_ID], [Hiredate], [Salary], [Commission], [Department_ID]) VALUES (6522, ‘MICHAEL’, ‘JUNIOR ANALYST’, 6566, CAST(‘1999-01-30’ AS Date), 30000, 2000, 20)

INSERT [dbo].[Employee] ([Employee_ID], [Employee_Name], [Job], [Manager_ID], [Hiredate], [Salary], [Commission], [Department_ID]) VALUES (6523, ‘ROCKY’, ‘BUSINESS CONSULTANT’, 6698, CAST(‘2011-02-06’ AS Date), 55000, 2000, 30)

INSERT [dbo].[Employee] ([Employee_ID], [Employee_Name], [Job], [Manager_ID], [Hiredate], [Salary], [Commission], [Department_ID]) VALUES (6524, ‘BELLA’, ‘JUNIOR ANALYST’, 6698, CAST(‘2017-04-11’ AS Date), 30000, 2000, 20)

INSERT [dbo].[Employee] ([Employee_ID], [Employee_Name], [Job], [Manager_ID], [Hiredate], [Salary], [Commission], [Department_ID]) VALUES (6525, ‘RUSSO’, ‘IT CONSULTANT’, 6721, CAST(‘2010-06-17’ AS Date), 65000, 2000, 30)

INSERT [dbo].[Employee] ([Employee_ID], [Employee_Name], [Job], [Manager_ID], [Hiredate], [Salary], [Commission], [Department_ID]) VALUES (6526, ‘AMIR’, ‘IT CONSULTANT’, 6722, CAST(‘1992-08-19’ AS Date), 60000, 2000, 20)

INSERT [dbo].[Employee] ([Employee_ID], [Employee_Name], [Job], [Manager_ID], [Hiredate], [Salary], [Commission], [Department_ID]) VALUES (1111, ‘TECHHOWDY’, ‘FOUNDER’, NULL, CAST(‘1980-01-01’ AS Date), 100000000, 100000, 1)

LIST OF QUESTIONS TO PRACTICE

  1. Display all the Employees who are getting 35000 and excess salaries in department 20
  2. Display all the Managers working in 20 & 30 department.
  3. Display all the Managers who don’t have a Manager
  4. Display all the employees who are getting some commission with their designation is neither MANANGER nor SENIOR ANALYST
  5. Display all the JUNIOR ANALYST whose name doesn’t ends with ‘S’
  6. Display all the Employees whose naming is having letter ‘E’ as the last but one character
  7. Display all the employees who total salary is more than 60000.
  8. Display all the employees who are getting some commission in department 30 & 40.
  9. Display all the managers whose name doesn’t start with A & S
  10. Display all the employees who earning salary not in the range of 25000 and 50000 in department 10 & 20
  1. Fetch All Records of Employee Table with Row ID.
  2. Fetch ALTERNATE records from Employee Table. (EVEN NUMBERED)
  3. Fetch ALTERNATE records from Employee Table. (ODD NUMBERED)
  4. Find the Employee with the 3rd Maximum Salary 
  5. Find the Employee with the 3rd Minimum Salary 
  6. Select the First Record From Table
  7. How to Get the Nth MAX Salary
  8. How to Delete Duplicate Rows From Employee
  9. Display the Number Of Employees in Each Department.
  10. Annual Salary for each Employee is provided – Now Display the Monthly and Annual Salary For each Employee.

ANSWERS FOR ABOVE QUESTIONS

ANSWERS FOR QUERIES BASED ON OPERATORS

  1. SELECT * FROM EMPLOYEE WHERE SALARY > 35000 AND DEPARTMENT_ID = 20;
  2. SELECT * FROM EMPLOYEE WHERE DEPARTMENT_ID IN(20,30) AND JOB = ‘MANAGER’;
  3. SELECT * FROM EMPLOYEE WHERE JOB = ‘MANAGER’ AND MANAGER_ID IS NULL;
  4. SELECT * FROM EMPLOYEE WHERE JOB NOT IN(‘MANAGER’, ‘SENIOR ANALYST’) AND COMMISSION > 0
  5. SELECT * FROM EMPLOYEE WHERE JOB = ‘JUNIOR ANALYST’ AND EMPLOYEE_NAME NOT LIKE ‘%S’
  6. SELECT * FROM EMPLOYEE WHERE EMPLOYEE_NAME LIKE ‘%E_’
  7. SELECT EMPLOYEE_NAME, SALARY, COMMISSION, JOB, (SALARY + COMMISSION) AS “TOTAL SALARY > 60K” FROM EMPLOYEE WHERE (SALARY + COMMISSION) > 60000
  8. SELECT EMPLOYEE_NAME, DEPARTMENT_ID, COMMISSION FROM EMPLOYEE WHERE COMMISSION > 0 AND DEPARTMENT_ID IN (30,40)
  9. SELECT * FROM EMPLOYEE WHERE JOB = ‘MANAGER’ AND EMPLOYEE_NAME NOT LIKE ‘A%’ AND EMPLOYEE_NAME NOT LIKE ‘S%’
  10. SELECT * FROM EMPLOYEE WHERE (SALARY NOT BETWEEN 25000 AND 50000) AND DEPARTMENT_ID IN(20,30)

ANSWERS COMPLEX SQL QUERIES



LIKE SHARE COMMENT

ALSO READ

List of 200 SQL Queries for Practice Before Interview Part -1

List of 200 SQL Queries for Practice Before Interview Part -2

List of 200 SQL Queries for Practice Before Interview Part -3

List of 200 SQL Queries for Practice Before Interview Part -4

TAGS

https://techhowdy.com/wp-content/uploads/2018/08/List-of-Practice-SQL-Server-Queries-for-Interview-2018.pnghttps://techhowdy.com/wp-content/uploads/2018/08/List-of-Practice-SQL-Server-Queries-for-Interview-2018-150x150.pngDemonDatabase Programmingbest practices in sql server query writing,best practices sql server queries,complex sql server queries for practice,complex sql server queries for practice with answers,practice of sql server queries,practice queries in sql server,practice sql server queries 2018,practice sql server queries online,practise sql server queries,sample sql server queries for practice before interview,sql queries practice sql server,sql server 2014 practice queries,sql server 2014 queries for practice,sql server 2017 queries for practice,sql server 2017 queries for practice pdf,sql server 2017queries practice,sql server practice queries pdf,sql server queries best practices,sql server queries examples for practice,sql server queries for practice,sql server queries for practice pdf,sql server queries for practice with answers,sql server queries for practice with answers pdf,sql server queries practice exercises,sql server queries to practiceWe have put together list of practice SQL Queries for Interview. Before you start practicing these SQL Queries, use the provided code to Create required Database tables. Fell free to modify these queries to find alternate methods to get the same answers. Use our forum to post questions related...Latest technology news