Top SQL Interview Questions and Answers for Freshers and Experienced (Simple Explanation)
SQL (Structured Query Language) is the backbone of databases. Whether you are a fresher starting your career or an experienced professional switching roles, SQL questions are asked in almost every interview.
Here are the most frequently asked SQL interview questions with easy-to-understand answers and examples.
1. What is SQL?
Answer:
SQL stands for Structured Query Language. It is used to communicate with databases — to store, update, retrieve, and delete data.
Example:
SELECT * FROM employees;
This command fetches all data from the “employees” table.
2. What is a database?
Answer:
A database is a collection of organized data that can be easily accessed, managed, and updated.
For example, a company’s employee data is stored in a database with tables like employees, departments, and salaries.
3. What are tables in SQL?
Answer:
A table is a structured set of data stored in rows and columns.
Row → single record
Column → specific attribute of that record
Example:
A table named Students can have columns like ID, Name, Age, Marks.
4. What are the different types of SQL statements?
Answer:
SQL statements are divided into five main types:
Type Purpose Example
DDL (Data Definition Language) Create/Modify structure CREATE TABLE
DML (Data Manipulation Language) Manage data INSERT, UPDATE, DELETE
DCL (Data Control Language) Manage permissions GRANT, REVOKE
TCL (Transaction Control Language) Manage transactions COMMIT, ROLLBACK
DQL (Data Query Language) Retrieve data SELECT
5. What is the difference between DELETE, TRUNCATE, and DROP?
Answer:
Command Function Rollback Structure
DELETE Removes specific rows ✅ Yes Structure remains
TRUNCATE Removes all rows ❌ No Structure remains
DROP Deletes the table completely ❌ No Structure removed
Example:
DELETE FROM students WHERE id = 3;
TRUNCATE TABLE students;
DROP TABLE students;
6. What is a Primary Key?
Answer:
A Primary Key uniquely identifies each record in a table. It cannot contain NULL or duplicate values.
Example:
CREATE TABLE employees (
emp_id INT PRIMARY KEY,
name VARCHAR(50)
);
7. What is a Foreign Key?
Answer:
A Foreign Key connects two tables — it links a column in one table to the Primary Key of another.
Example:
CREATE TABLE orders (
order_id INT PRIMARY KEY,
emp_id INT,
FOREIGN KEY (emp_id) REFERENCES employees(emp_id)
);
8. What is a Unique Key?
Answer:
A Unique Key also ensures all values in a column are different, but unlike Primary Key, a table can have multiple unique keys and it can contain a single NULL value.
9. What is a Join in SQL?
Answer:
A JOIN combines data from multiple tables based on related columns.
Types of Joins:
INNER JOIN: Returns matching rows only.
LEFT JOIN: Returns all rows from left table + matched rows from right.
RIGHT JOIN: Opposite of LEFT JOIN.
FULL JOIN: Returns all rows when there is a match in either table.
Example:
SELECT employees.name, departments.dept_name
FROM employees
INNER JOIN departments
ON employees.dept_id = departments.dept_id;
10. What is the difference between WHERE and HAVING?
Answer:
WHERE filters rows before aggregation.
HAVING filters after aggregation (used with GROUP BY).
Example:
SELECT dept_id, COUNT(*)
FROM employees
GROUP BY dept_id
HAVING COUNT(*) > 5;
11. What is GROUP BY used for?
Answer:
GROUP BY groups rows that have the same values into summary rows — often used with aggregate functions like COUNT, SUM, AVG.
Example:
SELECT department, COUNT(*)
FROM employees
GROUP BY department;
12. What are aggregate functions in SQL?
Answer:
Aggregate functions perform calculations on multiple values and return a single value.
Function Description
COUNT() Counts number of rows
SUM() Adds all values
AVG() Returns average
MIN() Finds smallest value
MAX() Finds largest value
13. What is an alias in SQL?
Answer:
An alias is a temporary name for a table or column.
Example:
SELECT name AS EmployeeName FROM employees;
14. What is the difference between IN and BETWEEN?
Answer:
IN checks if a value matches any value in a list.
BETWEEN checks if a value lies between two numbers.
Example:
SELECT * FROM employees WHERE dept_id IN (1,2,3);
SELECT * FROM employees WHERE salary BETWEEN 30000 AND 60000;
15. What is a subquery?
Answer:
A subquery is a query inside another query. It helps to fetch data used by the main query.
Example:
SELECT name
FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees);
16. What are constraints in SQL?
Answer:
Constraints are rules applied to table columns to maintain data accuracy and integrity.
Constraint Description
PRIMARY KEY Uniquely identifies a record
FOREIGN KEY Links two tables
UNIQUE No duplicates
NOT NULL Must have a value
CHECK Ensures condition is true
DEFAULT Adds a default value
17. What is normalization?
Answer:
Normalization is the process of organizing data to reduce redundancy and improve efficiency.
Common normal forms:
1NF: Remove repeating columns.
2NF: Remove partial dependency.
3NF: Remove transitive dependency.
18. What is denormalization?
Answer:
Denormalization means combining tables to reduce joins and improve read performance. It’s often used in reporting systems.
19. What are indexes and why are they used?
Answer:
An index improves the speed of data retrieval but slightly slows down insert and update operations.
Example:
CREATE INDEX idx_name ON employees(name);
20. What is a View in SQL?
Answer:
A View is a virtual table that stores a query result. It doesn’t store data physically.
Example:
CREATE VIEW high_salary AS
SELECT name, salary FROM employees WHERE salary > 60000;
21. What is a Stored Procedure?
Answer:
A stored procedure is a group of SQL statements stored in the database and executed together.
Example:
CREATE PROCEDURE GetEmployees()
AS
SELECT * FROM employees;
22. What is the difference between SQL and MySQL?
Answer:
SQL is the language used to manage data.
MySQL is a database management system that uses SQL to store and retrieve data.
23. What are NULL values in SQL?
Answer:
NULL means missing or undefined value.
To check NULL, use IS NULL or IS NOT NULL.
Example:
SELECT * FROM students WHERE marks IS NULL;
24. What is ORDER BY used for?
Answer:
It sorts the result set in ascending (ASC) or descending (DESC) order.
Example:
SELECT * FROM employees ORDER BY salary DESC;
25. What are the most common interview tips for SQL?
✅ Understand basic queries (SELECT, WHERE, GROUP BY, JOIN)
✅ Practice real examples instead of memorizing syntax
✅ Know how to use indexes and constraints
✅ Write queries on paper or notepad during mock practice
✅ Remember — clear logic > complex syntax!
Conclusion
These 25 simple SQL interview questions cover everything from the basics to commonly asked practical topics.
If you’re preparing for jobs like Data Analyst, Database Developer, Software Engineer, or Tester, mastering these concepts is enough to clear most SQL rounds.
Keep practicing with sample data and small projects. Real hands-on practice is the best teacher for SQL.