🟒 Top 100 SQL Interview Questions for 2 to 3 Years Experience(With Answers & Real Examples)

πŸ” Introduction

SQL interview questions for 2 Year Experience are one of the most common topics in technical interviews. If you are preparing for your first job, understanding SQL basics with examples is very important.

In this guide, you will learn:

  • Top 100 SQL interview questions

  • Simple, human-friendly answers

  • Real examples for better understanding


πŸ”Ή Basic SQL Questions (1–25)

1. What is SQL?
SQL is used to interact with databases like storing, updating, and retrieving data. It is widely used in backend systems.
πŸ‘‰ Example:

SELECT * FROM Employees;

2. What is a database?
A database is an organized collection of data stored electronically. It helps manage large data efficiently.
πŸ‘‰ Example: Employee database storing all employee records.


3. What is a table?
A table stores data in rows and columns. Each table represents a specific entity like users or products.
πŸ‘‰ Example: Employees table with Id, Name, Salary.


4. What is a row?
A row represents a single record in a table. Each row contains complete information about one entry.
πŸ‘‰ Example: One employee’s data.


5. What is a column?
A column represents a field in a table. It stores a specific type of data.
πŸ‘‰ Example: Name column stores employee names.


6. What is a primary key?
A primary key uniquely identifies each record. It cannot be null or duplicate.
πŸ‘‰ Example:

Id INT PRIMARY KEY

7. What is a foreign key?
A foreign key connects two tables. It refers to the primary key of another table.
πŸ‘‰ Example:

FOREIGN KEY (DeptId) REFERENCES Department(Id)

8. What is a unique key?
A unique key ensures all values are different. It allows one NULL value.
πŸ‘‰ Example:

Email VARCHAR(100) UNIQUE

9. What is NOT NULL?
It ensures a column cannot have null values.
πŸ‘‰ Example:

Name VARCHAR(50) NOT NULL

10. What is DEFAULT?
It assigns a default value if no value is provided.
πŸ‘‰ Example:

Salary INT DEFAULT 0

11. What is SELECT?
SELECT is used to retrieve data from a table.
πŸ‘‰ Example:

SELECT Name FROM Employees;

12. What is INSERT?
INSERT is used to add new records into a table.
πŸ‘‰ Example:

INSERT INTO Employees VALUES (1, 'John', 5000);

13. What is UPDATE?
UPDATE modifies existing records.
πŸ‘‰ Example:

UPDATE Employees SET Salary = 6000 WHERE Id = 1;

14. What is DELETE?
DELETE removes records from a table.
πŸ‘‰ Example:

DELETE FROM Employees WHERE Id = 1;

15. What is WHERE clause?
WHERE filters records based on conditions.
πŸ‘‰ Example:

SELECT * FROM Employees WHERE Salary > 5000;

16. What is ORDER BY?
ORDER BY sorts data in ascending or descending order.
πŸ‘‰ Example:

SELECT * FROM Employees ORDER BY Salary DESC;

17. What is DISTINCT?
DISTINCT removes duplicate values.
πŸ‘‰ Example:

SELECT DISTINCT DeptId FROM Employees;

18. What is COUNT()?
COUNT() returns number of rows.
πŸ‘‰ Example:

SELECT COUNT(*) FROM Employees;

19. What is SUM()?
SUM() calculates total value.
πŸ‘‰ Example:

SELECT SUM(Salary) FROM Employees;

20. What is AVG()?
AVG() calculates average value.
πŸ‘‰ Example:

SELECT AVG(Salary) FROM Employees;

πŸ”Ή Intermediate SQL Questions (26–60)

26. What is JOIN?
JOIN combines data from multiple tables.
πŸ‘‰ Example:

SELECT e.Name, d.Name FROM Employees e JOIN Dept d ON e.DeptId = d.Id;

27. Types of JOIN?
INNER, LEFT, RIGHT, FULL JOIN. Each works differently to fetch data.
πŸ‘‰ Example: INNER JOIN returns matching records.


28. What is INNER JOIN?
Returns matching records from both tables.
πŸ‘‰ Example:

SELECT * FROM A INNER JOIN B ON A.Id = B.Id;

29. What is LEFT JOIN?
Returns all records from left table and matched from right.
πŸ‘‰ Example:

SELECT * FROM A LEFT JOIN B ON A.Id = B.Id;

30. What is GROUP BY?
Groups rows with same values.
πŸ‘‰ Example:

SELECT DeptId, COUNT(*) FROM Employees GROUP BY DeptId;

31. What is HAVING?
Filters grouped data.
πŸ‘‰ Example:

SELECT DeptId, COUNT(*) FROM Employees GROUP BY DeptId HAVING COUNT(*) > 2;

32. What is subquery?
Query inside another query.
πŸ‘‰ Example:

SELECT * FROM Employees WHERE Salary > (SELECT AVG(Salary) FROM Employees);

33. What is IN operator?
Checks multiple values.
πŸ‘‰ Example:

SELECT * FROM Employees WHERE DeptId IN (1,2);

34. What is BETWEEN?
Filters range of values.
πŸ‘‰ Example:

SELECT * FROM Employees WHERE Salary BETWEEN 5000 AND 10000;

35. What is LIKE?
Used for pattern matching.
πŸ‘‰ Example:

SELECT * FROM Employees WHERE Name LIKE 'J%';

πŸ”Ή Advanced SQL Questions (61–85)

61. What is index?
Index improves query performance by speeding up search.
πŸ‘‰ Example:

CREATE INDEX idx_name ON Employees(Name);

62. What is normalization?
Organizing data to reduce redundancy.
πŸ‘‰ Example: Separate tables for Employees and Departments.


63. What is transaction?
A set of operations executed together.
πŸ‘‰ Example:

BEGIN TRANSACTION;

64. What is COMMIT?
Saves changes permanently.
πŸ‘‰ Example:

COMMIT;

65. What is ROLLBACK?
Undo changes.
πŸ‘‰ Example:

ROLLBACK;

66. What is stored procedure?
Reusable SQL code stored in DB.
πŸ‘‰ Example:

CREATE PROCEDURE GetData AS SELECT * FROM Employees;

67. What is trigger?
Auto-executed code on events.
πŸ‘‰ Example:

CREATE TRIGGER trg_insert ON Employees AFTER INSERT AS PRINT 'Inserted';

πŸ”Ή Practical SQL Questions (86–100)

86. How to find duplicate records?
Use GROUP BY with COUNT.
πŸ‘‰ Example:

SELECT Name, COUNT(*) FROM Employees GROUP BY Name HAVING COUNT(*) > 1;

87. How to delete duplicate records?
Use ROW_NUMBER() or GROUP BY.
πŸ‘‰ Example:

DELETE FROM Employees WHERE Id NOT IN (SELECT MIN(Id) FROM Employees GROUP BY Name);

88. How to get second highest salary?
Use subquery or ranking function.
πŸ‘‰ Example:

SELECT MAX(Salary) FROM Employees WHERE Salary < (SELECT MAX(Salary) FROM Employees);

89. How to get last record?
Use ORDER BY DESC with LIMIT/TOP.
πŸ‘‰ Example:

SELECT * FROM Employees ORDER BY Id DESC LIMIT 1;

90. What is SQL injection?
Security vulnerability using malicious queries.
πŸ‘‰ Example:

SELECT * FROM Users WHERE Username = '' OR '1'='1';

❓ FAQ :Β 

Q: How many SQL questions should a fresher prepare?
You should prepare at least 50–100 questions covering basics and queries.

Q: Is SQL important for interviews?
Yes, SQL is one of the most important skills for backend and data roles.


Leave a Comment

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

Scroll to Top