# **SQL Interview Questions – Set of 110**
## Here is a **comprehensive list of 110 SQL interview questions**. These are
categorized to cover foundational to advanced topics, including real-world problem-
solving, performance optimization, and system design-level questions.
### **A. Basic SQL (1–20)**
1. What is SQL?
2. What are the different types of SQL commands?
3. What is a primary key?
4. What is a foreign key?
5. What is the difference between WHERE and HAVING clauses?
6. What is the difference between UNION and UNION ALL?
7. How do you retrieve unique values from a column?
8. What are aggregate functions in SQL?
9. Explain the difference between CHAR and VARCHAR.
10. What is a NULL value in SQL?
11. How do you filter NULL values?
12. What does the DISTINCT keyword do?
13. How do you rename a column or table?
14. What is the ORDER BY clause used for?
15. What is the difference between DELETE, TRUNCATE, and DROP?
16. How can you change a column datatype?
17. How do you write a simple SELECT query?
18. How to retrieve records from two tables using JOIN?
19. What are constraints in SQL?
20. Explain the IN and BETWEEN operators.
---
### **B. Intermediate SQL (21–50)**
1. What is a JOIN? List different types of JOINs.
2. What is a self JOIN?
3. Explain the difference between INNER JOIN and OUTER JOIN.
4. What is a subquery?
5. What is a correlated subquery?
6. How do you update multiple columns in SQL?
7. What is the GROUP BY clause used for?
8. How does SQL handle NULLs in GROUP BY and ORDER BY?
9. What is a CASE statement? Provide an example.
10. How can you fetch the first N rows from a table?
11. How do you find duplicate records in a table?
12. How to delete duplicate rows from a table?
13. What is normalization?
14. What are the normal forms in database design?
15. What is denormalization?
16. What is a view in SQL?
17. How to update a view in SQL?
18. What is the difference between a view and a table?
19. What are indexes in SQL?
20. How do indexes affect performance?
21. What is a clustered index?
22. What is a non-clustered index?
23. What is the difference between a unique constraint and a primary key?
24. What is the use of the COALESCE function?
25. What is the difference between RANK, DENSE_RANK, and ROW_NUMBER?
26. What is a CTE (Common Table Expression)?
27. How do you use recursive CTEs?
28. What is a window function?
29. How does the OVER clause work in SQL?
30. What are transactions in SQL?
---
### **C. Advanced SQL (51–80)**
1. Explain ACID properties in a database.
2. What is a deadlock and how to avoid it?
3. How do you optimize a slow query?
4. What is query execution plan and how to use it?
5. What are stored procedures and functions?
6. What is the difference between a function and a stored procedure?
7. How do you implement error handling in SQL?
8. What are triggers in SQL?
9. How do you audit changes using triggers?
10. What are temp tables and when to use them?
11. What is the difference between temp table and table variable?
12. What is a materialized view?
13. What is sharding in databases?
14. What is partitioning in SQL?
15. How do you implement row-level security?
16. What is a sequence?
17. How to paginate records using SQL?
18. What is the difference between EXISTS and IN?
19. How do you handle many-to-many relationships in SQL?
20. How do you identify blocking queries?
21. What are the performance implications of joins?
22. How to analyze and fix slow-running queries?
23. How does indexing work in JOINs?
24. How to use indexed views?
25. What is lateral join?
26. How do you handle schema changes in production?
27. What is data skew and how to handle it?
28. What is the difference between OLAP and OLTP systems?
29. How do you write idempotent SQL scripts?
30. What is the difference between a cursor and WHILE loop?
---
### **D. Scenario-Based and Real-World SQL (81–100)**
1. Write a query to get the second highest salary.
2. How do you get top 3 products by revenue in each category?
3. Find all employees who joined in the last 3 months.
4. Write a query to calculate the running total.
5. Write a SQL to pivot rows to columns.
6. Unpivot columns into rows using SQL.
7. Find all orders without matching customers.
8. Write a query to get monthly revenue growth.
9. How to find gaps in a sequence of numbers?
10. Write a query to group data into time buckets (5-minute intervals).
11. Get customer churn rate from subscription data.
12. Find the longest streak of active days for a user.
13. How to perform fuzzy matching in SQL?
14. Write a query to calculate conversion rates.
15. Query to find overlapping date ranges.
16. Find products that were never sold.
17. Find the median of a numeric column.
18. Count number of distinct users per region per month.
19. Identify users who made purchases in the last two months but not before.
20. Write a query to remove HTML tags from strings.
---
### **E. DBA & DevOps-Level SQL (101–110)**
1. How do you take a backup of a database using SQL?
2. What are the tools to monitor SQL Server/MySQL/PostgreSQL performance?
3. How to automate SQL job scheduling?
4. What are the strategies to migrate data between two databases?
5. How do you version control your database schema?
6. What is blue-green deployment for SQL?
7. How to do zero-downtime deployments with SQL schema changes?
8. What are best practices for database security?
9. How do you handle large data imports efficiently?
10. How to audit and log database changes?