Ultimate SQL Interview Question Bank (Data Analyst Focus)
1. SQL Basics (Super Basic but Common in Interviews)
What is SQL?
Difference between SQL and MySQL/PostgreSQL/SQL Server?
Difference between SQL, PL/SQL, and T-SQL.
What is a database? Difference between DBMS and RDBMS.
What is a schema?
What is a table?
What is a row vs column?
What is a primary key? Can a table have multiple primary keys?
What is a composite key?
Difference between PRIMARY KEY and UNIQUE.
What are constraints? Name a few.
What is normalization? Explain 1NF, 2NF, 3NF, BCNF with examples.
What is denormalization? Why is it done?
Difference between OLTP and OLAP.
2. SQL Queries (Beginner Level)
Select all columns from a table.
Select only unique values from a column.
Query: Find employees whose salary > 50,000.
Query: Find all customers from "Delhi".
Query: Order employees by salary descending.
Query: Select first 5 rows from a table.
Query: Show records where salary is NULL.
Query: Find customers whose name starts with 'A'.
Query: Find customers whose name contains 'an'.
Difference between = and IN.
3. Joins (Core Interview Area)
Explain INNER, LEFT, RIGHT, FULL OUTER JOIN.
What is a cross join?
What is a self join? Example?
Query: Get list of employees with their department names.
Query: Find employees who don’t have managers.
Query: Find customers who placed orders but not payments.
Query: Find products that were never ordered.
Query: Show top N sales by joining orders and customers.
Tricky: Difference between LEFT JOIN WHERE col IS NULL vs NOT IN vs NOT EXISTS.
4. Aggregation + Grouping
Difference between COUNT(*), COUNT(col), and COUNT(DISTINCT col).
Query: Count number of employees in each department.
Query: Find average salary by department.
Query: Find department with max employees.
Query: Show customers who placed more than 5 orders.
Query: Find sum of sales grouped by month.
What happens if you use non-aggregated column without GROUP BY?
5. Subqueries + CTE
What is a subquery? Where can you use it?
Difference between correlated vs non-correlated subquery.
Query: Find employees earning more than avg salary.
Query: Return 2nd highest salary using subquery.
Query: Return 2nd highest salary using CTE.
Query: Find customers who spent more than avg spending of all customers.
Query: Show employees who joined before their manager (correlated subquery).
6. Window Functions (Must-Have)
What is the difference between RANK(), DENSE_RANK(), ROW_NUMBER()?
Query: Return top 3 salaries in each department.
Query: Running total of sales.
Query: Show month-wise average sales and difference from previous month.
Query: Find cumulative customers registered till each month.
Query: Find employees whose salary is higher than department average.
7. Functions (String, Date, Numeric)
Query: Convert name to upper case.
Query: Find length of employee names.
Query: Extract year from joining date.
Query: Find employees who joined in last 30 days.
Query: Calculate age of employees from DOB.
Query: Replace NULL salary with 0.
Query: Round sales amount to 2 decimals.
Query: Find day difference between two dates.
8. Advanced SQL (Theory + Queries)
What are indexes? Why do we need them?
Difference between clustered and non-clustered index.
What is a view? Difference between view and table.
What are stored procedures? Advantages?
What are triggers? Use cases?
What is a transaction?
Explain ACID properties.
Difference between UNION and UNION ALL.
Difference between EXCEPT, INTERSECT, and JOIN.
Query: Demonstrate CASE WHEN. (e.g. categorize employees into High/Medium/Low salary).
9. Real-World / Case Study Questions
Query: Find month-over-month growth of sales.
Query: Compare revenue this year vs last year.
Query: Find customer retention rate.
Query: Get top 5 products contributing to 80% of revenue (Pareto principle).
Query: Show daily cumulative sales (running sum).
Query: Pivot table — convert rows to columns.
Query: Show orders with multiple items vs single item.
Query: Find anomalies (e.g. negative sales or future dates).
10. Tricky / Brain Teaser SQL Questions
Query: Find Nth highest salary without using TOP/LIMIT.
Query: Find duplicate rows in a table.
Query: Delete duplicate rows but keep one copy.
Query: Find customers who ordered in consecutive months.
Query: Find employees who never got a promotion.
Query: Reverse a string in SQL.
Query: Swap values of two columns without using temp column.
Query: Find missing IDs in a sequence.
Query: Show 2nd and 3rd most sold product category.