Connect with us

Hi, what are you looking for?

Top 20 SQL Interview Questions and Answers for 2021
Top 20 SQL Interview Questions and Answers for 2021


Top 20 SQL Interview Questions and Answers for 2021

Having a Database is one of the crucial requirements of today’s industry. Wherein relational database is the most commonly used one. A relational Database basically has relations or, in easier words, a database where we can store data in the form of tables. Before you go in and attend a SQL interview, it is essential to know the various SQL interview questions for experienced professionals, or the SQL interview questions for freshers. So here we have a list of a few SQL interview questions which are likely to be asked in the interview.

Q1. What is a Database?

Ans. It is a place where we can store data in a systematic and organized manner. So that the retrieval of the data is easy.

Q2. What is SQL?

Ans. SQL stands for Structured Query Language. It is a standard query language which is used for maintaining relational databases and performing different tasks like manipulating data, accessing the data and so on.

Q3. What are the uses of SQL?

Ans. SQL is used for maintaining the database. Wherein we can create a new table or a database, read the data, update the data, retrieve the data or delete the data.

Q4. What is a Primary key?

Ans. Primary key is a constraint which is used to uniquely identify the records from the table. It is a combination of Unique and Not Null constraints. A table can have only one primary key and is recommended to have a primary key but not mandatory.

Q5. What is foreign key?

Ans. Foreign key is used to establish connection between any two tables. Also, a foreign key of one table can be related as the primary key for another table. We can have any number of foreign keys which can accept duplicate values and can be null.

Q6. What are SQL statements?

Ans. In SQL statements we have:

  1. DDL (Data Definition Language) which has Create, Alter, Rename, Truncate and Drop.
  2. DML (Data Manipulation Language) which has Insert, Update, Delete.
  3. DCL (Data Control Language) which has Grant, Revoke.
  4. TCL (Transmission Control Language) which has Commit, Savepoint, Rollback.
  5. DQL (Data Query Language) has Select, Projection, Selection and Joins.

Q7. What are Joins?

Ans. Joins are basically used to retrieve the data from multiple tables simultaneously. Types of Joins:

  1. Cartesian Join also known as Cross Join.
  2. Inner Join also known as Equi Join.
  3. Outer Join, which is further divided into:
  • Left Outer Join.
  • Right Outer Join.
  • Full Outer Join.
  1. Natural Join.
  2. Self Join.

Q8. What is Inner Join?

Ans. Inner Join is used to obtain only matched records using join condition. Join condition is a condition on which two tables are being merged.

Q9. What is Outer join?

Ans. Outer join is used to obtain both matches along with unmatched records from the table.

Q10. What are the different operators used in SQL?

Ans. We have

  2. Comparison Operators like =, !=, <, >, <=, >=.
  3. Logical Operators like AND, OR,NOT.
  4. Special Operators like IN, NOT IN, BETWEEN, NOT BETWEEN, IS, IS NOT, LIKE, NOT LIKE.

Q11. What is the query?

Ans. A database query is a code which is written in order to get data back from the database.

Q12. What is Subquery?

Ans. A query written inside another query is known as a subquery. It generally consists of an inner query that is executed first, and an output is generated. This output from the inner query is given to the outer query as an input. Taking this input from the inner query, the outer query executes completely and generates the result. So from here, we can say that the outer query depended on the inner query.

Q13. Why do I go for subquery?

Ans. When we have to find an unknown value, and when the data to be displayed is present in one table and the condition to be applied is present in another table, we go to subquery. Basically to establish connections between those two tables.

Q14. What are the types of subquery?

Ans. There two types of subquery: Correlated and Non-Correlated,

A correlated subquery is not considered as an independent query, but it can refer the column in the table listed in the FROM the list of the main query, whereas a non-correlated sub query can be considered as a independent query and the output of subquery are substituted in the main query.

Q15. What is the difference between drop and delete?

Ans. DROP is used to delete all the records along with the table structure, whereas DELETE is used to delete a single record.

Q16. What is the difference between truncate and drop?

Ans. TRUNCATE is used to delete all the records from the table but not the table structure, whereas in DROP we delete all the data along with the table structure.

Q17. Can we get back the table if we have already dropped the table?

Ans. Yes, we can get back the table by using the FLASHBACK statement. This statement is used to gain all the records along with the table structure as it is.

Q18. Write an SQL query to find the employee name which starts with A.


Q19.  Write a query to get the second maximum salary of an employee from the employee table.


Q20. Write a query to display employee name and salary, if the employee is getting a salary more than Adam.


This brings us to the end of the blog on SQL interview questions and answers. The above SQL interview questions would be helpful for fresher’s applying for the jobs as well for the people who have experience along with their few projects. These were a few basic examples that you could just brush up before your interview.

You May Also Like

Digital Logic Circuits

Excess-3 to BCD converter In this post on code conversions, we are going to see Excess-3 to BCD converter using k map technique.  K-map If you...


The Scientific Calculator is an advanced version of an ordinary calculator which helps us to solve complex arithmetic problems. The Normal Calculator consists of...

Digital Logic Circuits

BCD to Excess-3 converter In this post on a code converter, we are going to see BCD to Excess-3 converter using the k-mapping technique....


Tech Updates

If you’re a Microsoft Outlook user, what if suddenly some error occurs and you become unable to access your email account? No sending or...

Tech Updates

If you’re a Microsoft Outlook user, what if suddenly some error occurs and you become unable to access your email account? No sending or...


While running any establishment dealing with food preparation or catering professionally, there are multiple factors to take care of. Right from how the raw...

Health Care

In today’s world, when the lifestyle demands people to indulge in alcohol every once in a while, alcohol addiction can create havoc in one’s...

Tech Updates

HugosWay shields the individual data of its customers through SSL encryption in its PC and portable stages. HugosWay likewise encourages its customers through its...


In 2018, the Farm Bill legalized the use of CBD federally and in several states. Since then, this natural treatment’s become a popular alternative...