Whether you're applying for a role in data analytics, backend development, or database administration, SQL (Structured Query Language) remains one of the most essential skills employers look for. To help you prepare, we've compiled a list of the most commonly asked SQL interview questions along with clear and concise answers.
This guide is especially useful for freshers, working professionals, and anyone aiming to brush up on their SQL basics before an interview.
1. What is SQL?
Answer:
SQL stands for Structured Query Language. It is used to communicate with and manipulate databases. SQL allows users to perform tasks such as querying data, updating records, inserting data, and creating or modifying database structures.
2. What are the different types of SQL statements?
Answer:
SQL statements are mainly categorized into five types:
DDL (Data Definition Language) – CREATE, ALTER, DROP
DML (Data Manipulation Language) – SELECT, INSERT, UPDATE, DELETE
DCL (Data Control Language) – GRANT, REVOKE
TCL (Transaction Control Language) – COMMIT, ROLLBACK, SAVEPOINT
DQL (Data Query Language) – SELECT
3. What is the difference between WHERE and HAVING?
Answer:
WHERE is used to filter rows before any groupings are made.
HAVING is used to filter groups after the GROUP BY clause has been applied.
4. What is a primary key?
Answer:
A primary key is a column (or a set of columns) that uniquely identifies each row in a table. It must contain unique values and cannot contain NULLs.
5. What is a foreign key?
Answer:
A foreign key is a column that creates a relationship between two tables. It is a field in one table that refers to the primary key in another table, ensuring referential integrity.
6. What is the difference between INNER JOIN and LEFT JOIN?
Answer:
INNER JOIN returns only the matching rows from both tables.
LEFT JOIN returns all rows from the left table, along with the matched rows from the right table. If there is no match, NULL values are returned for columns from the right table.
7. How do you find duplicate records in a table?
Answer: You can use the GROUP BY and HAVING clauses to find duplicates:
sql
Copy
Edit
SELECT column_name, COUNT(*)
FROM table_name
GROUP BY column_name
HAVING COUNT(*) > 1;
8. What is normalization? What are its types?
Answer:
Normalization is the process of organizing data in a database to reduce redundancy and improve data integrity. Types include:
1NF (First Normal Form)
2NF (Second Normal Form)
3NF (Third Normal Form)
BCNF (Boyce-Codd Normal Form)
9. What is the difference between DELETE, TRUNCATE, and DROP?
Answer:
DELETE removes specified rows from a table and can be rolled back.
TRUNCATE removes all rows from a table but cannot be rolled back.
DROP removes the entire table structure from the database.
10. What is a subquery?
Answer: A subquery is a query nested inside another query. It is used to perform operations that depend on the result of another query. Subqueries can be used in SELECT, INSERT, UPDATE, or DELETE statements.
Final Thoughts
SQL is the backbone of any data-related job role. Whether you're aiming for a position in data analytics, software engineering, or database management, being confident with SQL concepts and query writing is crucial.
Make sure you don't just memorize answers—practice writing queries and solving real-life scenarios. Tools like LeetCode, HackerRank, and SQLZoo can be very helpful for hands-on practice.
Ready to master SQL and ace your interview? Let us know in the comments if you'd like a downloadable PDF or a mock test on SQL interview questions.
YOU ARE READING
Top SQL Interview Questions and Answers
Non-FictionPreparing for an SQL interview? This blog covers the most commonly asked SQL interview questions and answers to help you understand key concepts like joins, subqueries, normalization, and more. Perfect for freshers and working professionals looking...
