HomeSQL

SQL – Interview Questions & Answers – Part 2

SQL – Interview Questions & Answers – Part 2

1) What are the different types of Sub Queries?

Answer: The below is the answer for this question:

There are two types of Sub Queries:

  1. Single Row Sub Query
  2. Multi-Row Sub Query

For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:


2) What is distinct?

Answer: The below is the answer for this question:

distinct is a keyword used in SQL Select statements to retrieve the unique values.

For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:


3) Write an SQL Query to find the third maximum price from Products table?

Answer: The below is the answer for this question:

Select max(Price) from Products
where Price < (Select max(Price) from Products where Price < 
(Select max(Price) from Products));

For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:


4) What is the difference between Delete and Truncate?

Answer: The below is the answer for this question:

  • Delete is a DML command and Truncate is a DDL command.
  • Where clause can only be used in Delete command
  • Truncate cannot delete a single row from a table, where as Delete can
  • Rollback recovers the data with Delete only and cannot recover the data after Truncate.

For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:


5) Write an SQL Query to find the list of Employees who’s DOB is between ‘1925-11-25’ and ‘1955-11-25’?

Answer: The below is the answer for this question:

Select * from Employees
where BirthDate Between '1925-11-25' and '1955-11-25';

For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:


6) Write an SQL Query to find the list of Employees who were born in the year 1955?

Answer: The below is the answer for this question:

Select * from Employees 
where year(BirthDate)='1955';

For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:


7) Write an SQL Query to delete the duplicate records from a Table?

Answer: The below is the answer for this question:

delete e1 from employees e1
inner join employees e2
where e1.id < e2.id
and e1.firstname = e2.firstname
and e1.lastname = e2.lastname;

For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:


8) Write an SQL Query to find the City names which have 5 letters and ends with the letter ‘l’?

Answer: The below is the answer for this question:

Select Name from City where Name like '____l';

For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:


9) Write an SQL Query to find the Employees whose Salary between 300000 and 1000000?

Answer: The below is the answer for this question:

Select * from Employees
where Salary between 300000 and 1000000;

For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:


10) Write an SQL Query to find the Employees whose Salary >= 300000 and <= 1000000?

Answer: The below is the answer for this question:

Select * from Employees
where Salary between 300000 and 1000000;

For detailed answer with practical examples and explanation of this answer, you can check the below youtube video:


Please leave your questions/comments/feedback below.

Happy Learning 🙂

Arun Motoori ( www.QAFox.com )


Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *