Top 20 SQL Interview Questions and Answers (2025 Guide)

 If you are preparing for an SQL interview, whether for a fresher role or an experienced data engineer position, this guide will help you. We’ve listed the most frequently asked SQL interview questions and answers with examples, explained in simple language.

SQL (Structured Query Language) is the backbone of databases, and most IT companies expect you to have at least a basic to intermediate knowledge of SQL. Let’s get started.


Top 20 SQL Interview Questions and Answers (2025 Guide)



Top 20 SQL Interview Questions & Answers

1. What is SQL?

Answer:
SQL stands for Structured Query Language. It is used to store, manage, and retrieve data from relational databases such as MySQL, Oracle, SQL Server, and PostgreSQL.

2. What are the different types of SQL commands?

Answer:

  • DDL (Data Definition Language): CREATE, ALTER, DROP, TRUNCATE

  • DML (Data Manipulation Language): SELECT, INSERT, UPDATE, DELETE

  • DCL (Data Control Language): GRANT, REVOKE

  • TCL (Transaction Control Language): COMMIT, ROLLBACK, SAVEPOINT

3. What is the difference between DELETE, TRUNCATE, and DROP?

Answer:

  • DELETE: Removes rows from a table (can be rolled back).

  • TRUNCATE: Removes all rows quickly; cannot be rolled back.

  • DROP: Deletes the table structure completely.

4. What are primary key and foreign keys?

Answer:

  • Primary Key: A unique identifier for each row in a table.

  • Foreign Key: A field in one table that refers to the primary key of another table.

5. What is the difference between WHERE and HAVING?

Answer:

  • WHERE: Used to filter records before grouping.

  • HAVING: Used to filter groups after aggregation.

6. What is a JOIN in SQL?

Answer:
JOIN is used to combine rows from two or more tables based on related columns.
Types: INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN, SELF JOIN

7. Explain INNER JOIN vs LEFT JOIN.

Answer:

  • INNER JOIN: Returns only matching rows from both tables.

  • LEFT JOIN: Returns all rows from the left table and matching rows from the right.

8. What is the difference between UNION and UNION ALL?

Answer:

  • UNION: Combines results of two queries and removes duplicates.

  • UNION ALL: Combines results including duplicates.

9. What is a subquery?

Answer:
A subquery is a query inside another query, often used in WHERE or FROM clauses.

10. What are indexes in SQL?

Answer:
Indexes improve the speed of data retrieval.
Types: Clustered Index, Non-clustered Index.

11. What is normalization?

Answer:
Normalization is the process of organizing data to reduce redundancy.
Forms: 1NF, 2NF, 3NF, BCNF.

12. What is denormalization?

Answer:
Denormalization adds redundancy to improve performance by reducing complex joins.

13. What is a view in SQL?

Answer:
A view is a virtual table based on an SQL query. It stores no data itself but displays data from one or more tables.

14. What is the difference between CHAR and VARCHAR?

Answer:

  • CHAR: Fixed-length storage.

  • VARCHAR: Variable-length storage.

15. What is a stored procedure?

Answer:
A stored procedure is a set of SQL statements stored in the database and executed as a program.

16. What is a trigger in SQL?

Answer:
A trigger is an automatic action executed when a specific event (INSERT, UPDATE, DELETE) occurs in a table.

17. What is the ACID property in SQL?

Answer:

  • Atomicity, consistency, isolation, and durability → ensure reliable transactions.

18. What is the difference between OLTP and OLAP?

Answer:

  • OLTP: Online Transaction Processing → day-to-day operations.

  • OLAP: Online Analytical Processing → reporting & data analysis.

19. What are window functions in SQL?

Answer:
Functions like ROW_NUMBER(), RANK(), DENSE_RANK(), LEAD(), and LAG() are used for advanced analytics.

20. What is a CTE (Common Table Expression)?

Answer:
CTE is a temporary result set defined with WITH a clause and can be used in SELECT, INSERT, UPDATE, and DELETE statements.

Top 20 SQL Interview Questions and Answers (2025 Guide) Top 20 SQL Interview Questions and Answers (2025 Guide) Reviewed by Myray Publications on August 28, 2025 Rating: 5

No comments: