Posts

Showing posts from November, 2024

SQL interview questions

 Here’s a list of advanced SQL interview questions with answers to help you prepare effectively: 1. What is the difference between WHERE and HAVING clauses? Answer : WHERE filters rows before aggregation (GROUP BY), whereas HAVING filters rows after aggregation. Example: sql Copy code SELECT Department, COUNT ( * ) AS EmployeeCount FROM Employees WHERE Salary > 50000 GROUP BY Department HAVING COUNT ( * ) > 10 ; 2. What is a Common Table Expression (CTE)? How is it different from a subquery? Answer : A CTE is a temporary result set defined within a SQL statement using the WITH keyword. It improves readability and can be recursive. Example: sql Copy code WITH EmployeeCTE AS ( SELECT EmployeeID, ManagerID FROM Employees ) SELECT * FROM EmployeeCTE; Unlike a subquery, a CTE can be reused multiple times in the same query. 3. Explain Window Functions with an example. Answer : Window functions perform calculations across a set of rows related to the cu...