-

Homeapna IndiaTechnical SQL Interview Questions You Must Prepare in 2026

Technical SQL Interview Questions You Must Prepare in 2026

How to Find a Job in India

Master the Most Asked Technical SQL Interview Questions for 2026

SQL interviews in 2026 are less about remembering syntax and more about proving you can work with real data. Real data is incomplete, duplicated, late, and sometimes wrong. Interviewers also expect you to think about performance, not just correctness. A query that works on 10,000 rows but fails at 100 million is not “done”.

This blog covers the technical SQL questions you are most likely to face in 2026, plus what each question is actually testing, the traps candidates fall into, and how to practice in a way that translates to interviews.

What interviewers test in 2026 (quick map)

AreaWhat they look forTypical roles
Query correctnessJoins, filters, aggregations, NULL handlingAll roles
Analytical SQLWindow functions, ranking, time seriesAnalyst, BI, Data
Data cleaningDedupe, “latest record”, gap detectionData, Backend
PerformanceIndexing, query plans, sargabilityBackend, Data Eng
ReliabilityTransactions, isolation, concurrency issuesBackend, Platform

If you cover these five areas, you are already ahead of most candidates.

Fundamentals that still eliminate candidates

1. WHERE vs HAVING

Question: What is the difference between WHERE and HAVING?

What it tests: Understanding of filtering before vs after aggregation.

  • WHERE filters rows before aggregation
  • HAVING filters groups after aggregation

Common trap: Trying to filter aggregated values using WHERE.

COUNT(*) vs COUNT(column)

Question: When do COUNT(*) and COUNT(col) return different results?

What it tests: NULL behavior.

  • COUNT(*) counts rows
  • COUNT(col) counts non-NULL values in col

Follow-up they like: How would you count distinct non-NULL users?
Answer pattern: COUNT(DISTINCT user_id) (and be aware of DB-specific behavior around NULLs).

Execution order (mental model)

Interviewers do not need you to recite the full optimizer logic, but they want you to understand why something works.

ClauseConceptual order
FROM + JOINBuild row set
WHEREFilter rows
GROUP BYCreate groups
HAVINGFilter groups
SELECTCompute projection
ORDER BYSort
LIMIT / FETCHReturn subset

Why it matters: It helps you reason about why an alias works in ORDER BY but not in WHERE in most SQL dialects.

Joins: where “working SQL” still produces wrong answers

INNER JOIN vs LEFT JOIN, and how LEFT JOIN accidentally becomes INNER

Question: Explain the difference between INNER JOIN and LEFT JOIN. When does a left join behave like an inner join?

What it tests: Real-world debugging.

Key concept: LEFT JOIN keeps all rows from the left table. But if you add a WHERE filter on a right-table column that rejects NULLs, you remove the unmatched rows.

Example trap:
“Show all users and their last order, even if they have none”
Then someone adds: WHERE orders.status = ‘DELIVERED’
That removes users with no orders because orders.status becomes NULL.

Better approach: Move that condition into the join condition or handle NULL safely.

Join duplicates and “unexpected inflated counts”

Question: Why did my count double after adding a join?

What it tests: Understanding of join cardinality.

Answer approach:

  • Many-to-many joins multiply rows
  • Aggregations after joins can inflate metrics
  • Fix by aggregating before joining, joining on unique keys, or using COUNT(DISTINCT …) depending on the metric definition

Interview tip: Ask what the metric is. “Total orders” vs “unique customers who ordered” lead to different correct queries.

NULL logic (small topic, big impact)

NULL comparisons and tri-valued logic

Question: Why does WHERE col = NULL not work?

What it tests: Understanding that NULL is “unknown”, not a value.
Use IS NULL and IS NOT NULL.

Bonus point: Explain how NULL affects NOT IN. If the subquery returns NULL, NOT IN can return no rows. Many interviewers love this gotcha.

Aggregations and grouping (interview favorites)

“Find duplicate rows”

Question: Find duplicate emails in a users table.

What it tests: Grouping and HAVING.
Basic pattern: group by the field and filter groups with count greater than 1.

Follow-up: What if emails differ only by case or spaces?
Good answer: normalize in a derived step (lowercase, trim) and dedupe on normalized value, but be careful because normalization rules depend on product logic.

“Second highest salary” (with and without duplicates)

Question: Find the second highest salary.

What it tests: Handling duplicates and clarity.
Ask: “Second highest distinct salary or second record by salary?”
That one question signals maturity.

Window functions (high-frequency in 2026)

Window functions are no longer “nice to have”. Many interviews assume you can use them.

ROW_NUMBER vs RANK vs DENSE_RANK

Question: What is the difference between ROW_NUMBER(), RANK(), and DENSE_RANK()?

FunctionTiesGaps in rankingWhen to use
ROW_NUMBERNoNo“Pick exactly one row per group”
RANKYesYes“Ranking where gaps are acceptable”
DENSE_RANKYesNo“Top N per group, include ties cleanly”

Practical example: Top 3 salaries per department.

  • Use DENSE_RANK if ties should all be included
  • Use ROW_NUMBER if you need exactly 3 rows regardless of ties

“Latest record per user”

Question: For each user, return the most recent transaction.

What it tests: Partitioning, ordering, and deterministic selection.
Pattern: ROW_NUMBER() OVER (PARTITION BY user ORDER BY created_at DESC) then filter = 1.

Extra credit: Mention tie-breakers. If two rows have same timestamp, order by a unique id as second sort.

Running totals and moving windows

Question: Compute a running total of revenue by date, and also a 7-day moving average.

What it tests: Window frames.

What to say:

  • Running total uses SUM(…) OVER (ORDER BY date)
  • Moving average needs a frame: ROWS BETWEEN 6 PRECEDING AND CURRENT ROW

Common trap: Confusing ROWS vs RANGE. RANGE can group equal values and behave unexpectedly with duplicates.

CTEs: clarity and multi-step thinking

12. CTE vs subquery

Question: When do you use a CTE instead of a subquery?

What it tests: Readability and reasoning.
A strong answer:

  • Use CTEs to break logic into steps
  • It improves reviewability and reduces mistakes
  • Be aware that some databases may materialize CTEs in certain cases, so check performance if a query is critical

Recursive CTEs (hierarchy problems)

Question: Return the reporting chain for each employee.

What it tests: Structured thinking with graphs.
Even if you do not code it perfectly, showing that you know recursion exists in SQL and you would guard against cycles is a good sign.

Data cleaning patterns that show up in real work

Deduplicate and keep the latest

Question: Remove duplicates based on (email, phone) and keep the latest updated row.

What it tests: A real-world pattern used in pipelines.

Recommended approach:

  1. Rank rows within each duplicate group by updated_at DESC
  2. Keep rank 1

What they may ask next: If “latest” is not enough, how do you merge fields?
Answer: define merge rules per column (prefer non-NULL, prefer verified sources) and implement using conditional logic.

Gap detection (missing days, missing sequence ids)

Question: Identify missing dates in a daily metrics table.

What it tests: Time series reasoning.
You might generate a calendar table or use a date series feature depending on the database, then left join and filter missing.

Performance and query optimization (the 2026 separator)

In many interviews, once your SQL works, they ask, “How would you make it faster?”

Index basics and trade-offs

Question: What is an index and when can it make things worse?

What it tests: Production awareness.

Good answer points:

  • Index speeds reads for selective filters and join keys
  • Index slows writes because it must be maintained
  • Too many indexes increase storage and can hurt overall performance

Sargability (why functions in WHERE are costly)

Question: Why is WHERE DATE(created_at) = ‘2026-01-01’ often slow?

What it tests: Whether you know how indexes are used.
Applying a function to an indexed column can prevent index usage.

Better pattern: filter by a range:

  • created_at >= ‘2026-01-01’ AND created_at < ‘2026-01-02’

Query plan approach (how you actually debug)

Interviewers want a method, not magic.

StepWhat you check
1Confirm expected row counts after each join
2Check filters: are you reducing data early?
3Verify join keys: are they indexed and correct type?
4Look for scans vs seeks (or equivalent)
5Remove functions on indexed columns in WHERE/JOIN
6Consider pre-aggregation, materialized views, or partitioning if needed

You do not need to name every plan operator. You just need to show you can reason systematically.

Transactions, isolation, and concurrency (backend interviews)

ACID and isolation anomalies

Question: What does ACID mean? What issues do isolation levels prevent?

What it tests: Reliability fundamentals.

Expected coverage:

  • Dirty reads
  • Non-repeatable reads
  • Phantom reads

You can keep it simple: higher isolation reduces anomalies but can reduce concurrency.

Deadlocks and prevention

Question: What is a deadlock and how do you reduce it?

What it tests: Real incident experience.

Good answer:

  • Keep transactions short
  • Lock rows in consistent order across code paths
  • Use proper indexes so queries lock fewer rows
  • Use retries with backoff for deadlock errors

A focused 2026 practice plan (without wasting time)

If you want a practical plan, use this set. It covers most interview surfaces.

Practice setProblems to master
Joins + aggregationjoin inflation, left join filters, group metrics
Windowstop N per group, latest row per group, running totals
Data qualitydedupe keep latest, NULL pitfalls, NOT IN issue
Performancesargability, index choices, plan-driven debugging
Transactionsbasic ACID + deadlock scenario reasoning

Aim for 20 to 25 problems, but write them cleanly and explain your choices. That is more valuable than solving 200.

FAQ’S About Technical SQL Interview Questions

1) Do I need to memorize SQL syntax for every database?
No. Most interviews accept standard SQL. What matters is your logic, your edge case handling, and your ability to explain.

2) Are window functions mandatory for 2026 interviews?
For data roles, yes. For backend roles, increasingly yes, especially for reporting, ranking, and deduping patterns.

3) What matters more: correctness or performance?
Correctness first. Then show performance awareness by explaining how you would reduce scanned rows and use indexes.

4) What are the most common reasons candidates fail SQL rounds?
Join duplicates inflating metrics, NULL misunderstandings, and not clarifying requirements like ties, distinct counts, or “latest” definitions.

5) Should I ask clarifying questions in an interview?
Yes, one clear clarification is a strong signal. Examples: ties included or not, time zone, distinct vs total, and definitions of “active”.

Category

Looking for a new opportunity?

Get access to over 5000 new job openings everyday across India.