Forum

Top 25 SQL Intervie...
 
Share:
Notifications
Clear all

Top 25 SQL Interview Questions Asked in TCS, Infosys & Accenture (2025 Edition)

1 Posts
1 Users
0 Reactions
768 Views
Posts: 134
Admin
Topic starter
(@sql-admin)
Reputable Member
Joined: 6 years ago

If you’re preparing for SQL interviews at TCS, Infosys, or Accenture in 2025, this guide is your ultimate resource. These top 25 SQL interview questions are based on real-world technical rounds asked by leading MNCs.

Whether you’re a fresher, data analyst, or experienced SQL developer, these questions cover everything — from basic SELECT queries to advanced joins, window functions, and performance tuning.


🔹 Top 25 SQL Interview Questions & Answers (2025 Edition)

1. What is the difference between INNER JOIN and LEFT JOIN?

👉 Answer:

  • INNER JOIN returns only matching records between two tables.

  • LEFT JOIN returns all records from the left table, and matching ones from the right.


2. How do you find the 2nd highest salary from the Employee table?

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

Used frequently in TCS & Accenture interviews.


3. What is the difference between WHERE and HAVING clauses?

  • WHERE filters rows before grouping.

  • HAVING filters groups after aggregation.


4. How do you find duplicate records in a table?

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

5. What is a Window Function in SQL?

A window function performs calculations across a set of table rows related to the current row.
Example:

 
SELECT Name, Salary, RANK() OVER (ORDER BY Salary DESC) AS Rank
FROM Employees;

6. Explain normalization and its types.

Normalization reduces redundancy.

  • 1NF: Atomic values

  • 2NF: Remove partial dependency

  • 3NF: Remove transitive dependency


7. Difference between DELETE, TRUNCATE, and DROP.

CommandRemoves DataRollbackStructure Remains
DELETEYesYesYes
TRUNCATEYesNoYes
DROPYesNoNo

8. What are indexes in SQL and why are they used?

Indexes improve query performance by reducing disk I/O. However, too many indexes can slow down inserts and updates.


9. Write a query to display employees with even Employee IDs.

 
SELECT * FROM Employees WHERE EmployeeID % 2 = 0;

10. Explain the difference between UNION and UNION ALL.

  • UNION removes duplicates.

  • UNION ALL includes duplicates for faster performance.


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

CTEs are temporary result sets used for better readability.

 
WITH CTE AS (
SELECT Department, COUNT(*) AS EmpCount
FROM Employees
GROUP BY Department
)
SELECT * FROM CTE WHERE EmpCount > 5;

12. How do you optimize a slow SQL query?

  • Use proper indexes

  • Avoid **SELECT ***

  • Check execution plans

  • Limit subqueries using JOINs


13. What is the difference between primary key and unique key?

  • Primary Key: Only one allowed per table, cannot be NULL.

  • Unique Key: Multiple allowed, can contain one NULL value.


14. How can you find employees who earn more than their managers?

 
SELECT e.Name
FROM Employees e
JOIN Employees m ON e.ManagerID = m.EmployeeID
WHERE e.Salary > m.Salary;

15. What is the purpose of the COALESCE function?

Replaces NULL values with specified values.

 
SELECT COALESCE(ManagerName, 'Not Assigned') FROM Employees;

16. Explain self join with example.

A self join is a join of a table to itself.
Used to compare rows within the same table.


17. What is a Subquery?

A query inside another query.
Types: Scalar, Correlated, and Non-correlated.


18. How do you delete duplicate rows but keep one?

 
DELETE FROM Employees
WHERE RowID NOT IN (
SELECT MIN(RowID)
FROM Employees
GROUP BY Name, Salary
);

19. What are transactions in SQL?

A transaction is a set of SQL operations treated as a single unit — either all succeed or fail.
Commands: BEGIN, COMMIT, ROLLBACK


20. What is ACID in SQL transactions?

Atomicity, Consistency, Isolation, Durability — ensures data integrity.


21. What are aggregate functions in SQL?

COUNT(), AVG(), SUM(), MAX(), MIN()


22. Difference between clustered and non-clustered index.

  • Clustered: Sorts actual table data. One per table.

  • Non-clustered: Stores separate structure. Multiple allowed.


23. How do you use CASE in SQL?

 
SELECT Name,
CASE
WHEN Salary > 50000 THEN 'High'
ELSE 'Low'
END AS Category
FROM Employees;

24. How can you join more than two tables?

You can chain multiple JOINs using ON clauses.


25. What is the difference between EXISTS and IN?

  • IN compares against a list.

  • EXISTS checks for the existence of rows from a subquery (faster in large datasets).


💡 Conclusion

Mastering these 25 SQL interview questions can help you crack your next interview with TCS, Infosys, or Accenture easily. Practice them in a live SQL editor and focus on understanding why each query works — not just how.


Leave a reply

Author Name

Author Email

Title *

 
Preview 0 Revisions Saved
Share: