0% found this document useful (0 votes)
26 views

Accenture_SQL_Interview_QnA

Uploaded by

dheshkapradan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Accenture_SQL_Interview_QnA

Uploaded by

dheshkapradan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Accenture SQL Interview Questions and Answers

SQL Interview Questions and Answers

Q: What is the difference between DELETE and TRUNCATE?

A: DELETE removes rows one by one based on a condition and can be rolled back, whereas

TRUNCATE removes all rows and cannot be rolled back.

Q: How do you optimize a slow SQL query?

A: Optimize by using proper indexes, avoiding SELECT *, analyzing the execution plan, optimizing

joins, and caching frequently accessed data.

Q: What is the difference between INNER JOIN and LEFT JOIN?

A: INNER JOIN returns rows where there is a match in both tables, while LEFT JOIN returns all

rows from the left table and matching rows from the right table.

Q: What is the difference between a PRIMARY KEY and a UNIQUE key?

A: PRIMARY KEY ensures uniqueness and cannot have NULL values, while a UNIQUE key also

ensures uniqueness but can allow NULL values.

Q: Explain GROUP BY and HAVING with an example.

A: GROUP BY groups rows by specified columns, and HAVING filters groups based on a condition.

Example: SELECT Department, COUNT(*) FROM Employees GROUP BY Department HAVING

COUNT(*) > 10;

Q: How do you find the second highest salary from an Employee table?

A: Using LIMIT and OFFSET or a subquery. Example: SELECT MAX(Salary) FROM Employee

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

Q: What is a CROSS JOIN?


A: CROSS JOIN produces the Cartesian product of two tables, combining each row of the first table

with all rows from the second table.

Q: What is a stored procedure, and why is it used?

A: A stored procedure is a set of SQL statements stored and executed on the server, used for

reducing network traffic, improving performance, and enhancing security.

Q: What are window functions? Give an example.

A: Window functions perform calculations across a set of table rows related to the current row.

Example: SELECT EmployeeID, Salary, ROW_NUMBER() OVER (PARTITION BY Department

ORDER BY Salary DESC) FROM Employees;

Q: How do you handle duplicate records in a table?

A: To find duplicates: SELECT Column1, Column2, COUNT(*) FROM TableName GROUP BY

Column1, Column2 HAVING COUNT(*) > 1. To remove duplicates, use ROW_NUMBER() and

delete rows with RowNum > 1.

You might also like