Introduction
SQL remains one of the highest-signal skills in modern hiring loops, not only for data roles but also for backend, product, and analytics-heavy positions. In 2026, interviewers are less interested in memorized syntax and more focused on your ability to reason through ambiguous data problems.
This guide covers the SQL interview questions that appear most often and explains what strong answers look like.
Foundational SQL Questions
1) What is the difference between WHERE and HAVING?
WHERE filters rows before aggregation. HAVING filters groups after aggregation.
SELECT department, COUNT(*) AS headcount
FROM employees
WHERE active = true
GROUP BY department
HAVING COUNT(*) > 10;
2) What is the difference between INNER JOIN, LEFT JOIN, and FULL OUTER JOIN?
INNER JOIN: returns matching rows in both tables.LEFT JOIN: returns all rows from the left table plus matches from the right.FULL OUTER JOIN: returns all rows from both tables, matched where possible.
Interview tip: always explain how nulls appear in non-matching rows.
3) How do GROUP BY and aggregate functions work together?
GROUP BY creates groups of rows sharing the same values. Aggregates like COUNT, SUM, and AVG then compute one value per group.
4) What are primary keys and foreign keys?
- A primary key uniquely identifies each row in a table.
- A foreign key references a primary key in another table to enforce relational integrity.
5) What is normalization, and when would you denormalize?
Normalization reduces redundancy and update anomalies. Denormalization is useful when read performance matters more than strict normalization, especially in analytics or reporting workloads.
Intermediate SQL Questions
6) How do window functions differ from aggregate functions?
Aggregate functions collapse rows into one row per group. Window functions compute values across a partition without collapsing row-level detail.
SELECT
customer_id,
order_id,
order_total,
SUM(order_total) OVER (PARTITION BY customer_id ORDER BY created_at) AS running_total
FROM orders;
7) What is the difference between ROW_NUMBER, RANK, and DENSE_RANK?
ROW_NUMBER: unique sequence (no ties).RANK: ties share rank and skip subsequent numbers.DENSE_RANK: ties share rank but no gaps.
8) How do you find duplicates in a table?
SELECT email, COUNT(*) AS duplicates
FROM users
GROUP BY email
HAVING COUNT(*) > 1;
Strong candidates also explain how they would resolve duplicates safely in production.
9) How do CTEs improve query readability?
CTEs (Common Table Expressions) break complex logic into named steps. They help debugging, improve maintainability, and reduce mental overhead in interviews.
10) What is the difference between DELETE, TRUNCATE, and DROP?
DELETE: removes selected rows (can useWHERE).TRUNCATE: removes all rows quickly, usually with fewer logs.DROP: removes the table schema and data.
Advanced SQL Questions
11) How do you optimize a slow SQL query?
A strong framework:
- Validate the baseline with
EXPLAINorEXPLAIN ANALYZE. - Check full table scans and high-cardinality joins.
- Add or refine indexes based on filter/join patterns.
- Remove unnecessary columns and nested subqueries.
- Test performance impact with representative data volumes.
12) What is indexing, and what are index tradeoffs?
Indexes speed up read queries but add storage overhead and can slow writes. Good answers discuss B-tree behavior, selective columns, and over-indexing risk.
13) How would you design a query for top N per group?
WITH ranked AS (
SELECT
department,
employee_id,
salary,
ROW_NUMBER() OVER (PARTITION BY department ORDER BY salary DESC) AS rn
FROM employees
)
SELECT department, employee_id, salary
FROM ranked
WHERE rn <= 3;
14) How do transactions and isolation levels affect correctness?
Interviewers want to hear how you prevent dirty reads, non-repeatable reads, and phantom reads based on the workload and consistency requirements.
15) What is the difference between OLTP and OLAP workloads?
- OLTP: high-frequency transactional reads/writes, low latency, strict consistency.
- OLAP: analytical queries over large datasets, scan-heavy, often batch-oriented.
Practical Scenario Questions
Scenario 1: You need daily active users by platform for the last 30 days.
Explain your approach:
- define the activity event clearly,
- filter by date range,
- deduplicate users per day and platform,
- aggregate and order for dashboard consumption.
Scenario 2: Revenue dashboard numbers do not match finance reports.
Strong candidates walk through:
- source-of-truth table checks,
- timezone handling,
- refund and cancellation logic,
- duplicate event detection,
- reconciliation query comparisons.
Common SQL Interview Mistakes
- Writing a query first without clarifying assumptions.
- Ignoring null handling and edge cases.
- Using nested subqueries when a window function is cleaner.
- Not discussing performance and index implications.
- Failing to explain tradeoffs clearly.
7-Day SQL Interview Prep Plan
- Day 1: joins, filtering, grouping fundamentals.
- Day 2: aggregations and edge-case handling.
- Day 3: window functions and ranking.
- Day 4: CTEs, subqueries, and query readability.
- Day 5: indexing and optimization strategies.
- Day 6: scenario-based business SQL questions.
- Day 7: timed mock interview and review.
Final Takeaway
You do not need to memorize every SQL function. You need to demonstrate structured thinking, clear assumptions, and production-aware decision making.
If you can explain your query logic and tradeoffs with confidence, you will outperform most candidates.
