📘 SQL Interview Questions (Complete +
Real-Time Scenarios)
📘 Basics
1. What is SQL?
2. Difference between SQL and NoSQL?
3. What are DDL, DML, DCL, TCL?
4. What are constraints in SQL? (PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK,
DEFAULT)
5. Difference between schema and database?
6. Difference between CHAR, VARCHAR, NVARCHAR, TEXT?
7. Difference between primary key, unique key, and foreign key?
8. What is OLTP vs OLAP?
📘 Joins
9. Difference between INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL OUTER JOIN?
10. What is a SELF JOIN?
11. What is a CROSS JOIN?
12. Difference between UNION and UNION ALL?
13. How to join three or more tables?
📘 Subqueries & CTE
14. Difference between correlated and non-correlated subquery?
15. What is a CTE (Common Table Expression)?
16. What is a recursive CTE?
📘 Aggregations & Window Functions
17. What are aggregate functions in SQL?
18. Difference between WHERE and HAVING?
19. Difference between ROW_NUMBER(), RANK(), and DENSE_RANK()?
20. What are LEAD() and LAG() functions?
21. How do you calculate running totals?
22. How do you calculate moving averages?
📘 DDL & DML
23. Difference between DELETE, TRUNCATE, DROP?
24. Syntax for INSERT, UPDATE, DELETE?
25. How to update multiple rows at once?
26. Difference between TRUNCATE and DROP?
📘 Indexing & Performance
27. Difference between clustered and non-clustered index?
28. Types of indexes in SQL?
29. How do indexes improve performance?
30. Disadvantages of indexing?
31. How to create and drop an index?
32. How to optimize a slow SQL query?
📘 Advanced SQL
33. Difference between stored procedure and function?
34. What is a trigger in SQL?
35. How do you prevent SQL injection?
36. Explain transactions and ACID properties?
37. What is partitioning in SQL?
38. Difference between materialized view and normal view?
📘 Real-Time Business & Product Analytics
39. How to calculate user retention (D1, D7, D30)?
40. How to calculate churn rate of customers?
41. How to build a user funnel (impression → click → add-to-cart → purchase)?
42. How to calculate conversion rate at each funnel stage?
43. How to calculate repeat purchase rate?
44. How to find power users who log in 5+ times per week?
45. How to find inactive users in the last 60 days?
46. How to calculate customer lifetime value (CLV)?
47. How to calculate average time between two purchases?
48. How to calculate drop-off rate between two funnel steps?
49. How to identify users who upgraded from free → paid plan?
50. How to measure cohort-based retention (users grouped by signup month)?
51. How to calculate stickiness ratio (DAU/MAU)?
52. How to calculate revenue churn vs user churn?
53. How to find the most common user journey path from events data?
54. How to detect users with 3 consecutive errors or failures?
55. How to calculate session length and number of sessions per user?