Skip to content

SQL interview questions Indian companies ask, with answers

Joins, window functions, live query tasks and conceptual follow-ups - the SQL interview questions Indian companies ask most.

4 min read
Illustration of a desk with a database cylinder, laptop, notebook and plant, representing SQL interview preparation

The SQL interview questions Indian companies ask most are joins, GROUP BY with HAVING, window functions, the difference between WHERE and HAVING, and writing a query live on a shared screen. Whether you are interviewing at a startup, an IT services giant or a product company, 80% of the SQL round comes from a small set of patterns. This guide covers those patterns with the questions, the expected answers, and the follow-ups interviewers use to separate memorisation from real understanding.

The core questions every interviewer asks

Prepare these first; they appear in nearly every SQL round. What is the difference between WHERE and HAVING? (WHERE filters rows before grouping, HAVING filters groups after aggregation.) What is the difference between DELETE, TRUNCATE and DROP? (DELETE removes rows with a WHERE option and can roll back; TRUNCATE removes all rows faster without row-level logging; DROP removes the table itself.) What is a primary key vs a unique key? (A primary key is one per table and cannot be NULL; a table can have many unique keys that allow one NULL.) What are the types of joins? (INNER, LEFT, RIGHT, FULL OUTER, CROSS - and be ready to draw the Venn diagram from memory.) These are screening questions: missing them usually ends the round early.

Joins cheat table

JoinReturnsTypical interview trap
INNER JOINOnly matching rows in both tablesSilently drops unmatched rows you expected to keep
LEFT JOINAll left rows, matched or notNULLs on the right side that break later filters
RIGHT JOINAll right rows, matched or notRarely needed; rewrite as LEFT for readability
FULL OUTER JOINAll rows from both sidesNot supported in older MySQL; emulate with UNION
CROSS JOINEvery row paired with every rowUsually a missing join condition, not intent

Live query questions you will have to write

Product and analytics companies make you write queries in a shared editor. The five most common tasks: find the second highest salary (use a subquery with MAX excluding the top value, or DENSE_RANK), find duplicate emails in a table (GROUP BY email HAVING COUNT(*) greater than 1), get the top N rows per group (ROW_NUMBER partitioned by the group), employees earning more than their managers (self-join on manager id), and running totals (SUM OVER ORDER BY). Practice writing these from scratch, not recognising them - interviewers change table names and one condition, and memorised answers fall apart under small changes.

Window functions: the new filter question

Since 2023, window functions have become the standard separator in Indian data interviews. Know ROW_NUMBER, RANK and DENSE_RANK cold, including how ties behave in each (RANK skips numbers after ties, DENSE_RANK does not). Understand that window functions compute after the WHERE clause, which is why you cannot filter on them directly and need a subquery or CTE. A typical follow-up: "rank employees by salary within each department, then keep only the top two per department" - the answer is ROW_NUMBER over a partition wrapped in a CTE with a WHERE on the rank column.

Conceptual follow-ups that reveal depth

After the basics, interviewers probe understanding. What is normalization and when would you denormalize? (Reduce redundancy up to 3NF for transactional systems; denormalize deliberately in reporting tables for read speed.) What is an index and when does it hurt? (It speeds reads but slows writes; too many indexes on a write-heavy table backfire.) What is the difference between UNION and UNION ALL? (UNION deduplicates; UNION ALL is faster and keeps duplicates.) What is a correlated subquery? (A subquery that references the outer row and runs once per row - often replaceable with a join.) Answer with a one-line definition plus a concrete example; that structure signals real experience.

How to practice in the final week

Three days of pattern drills beat two weeks of passive reading. Day one: joins and aggregations, writing ten queries by hand. Day two: window functions until the PARTITION BY syntax is automatic. Day three: explain your queries aloud while writing them, because interviewers score your narration as much as the output. Our interview question bank has SQL and data-role question sets with an AI mock interview that follows up on your answers the way a real interviewer does, including the "why not a join instead?" probes. Live data-role openings are listed on our jobs section. If the role touches analytics, also revise basic query optimisation: reading an EXPLAIN plan and knowing why SELECT star is a red flag.

Frequently asked questions

Which SQL dialect should I learn for interviews?

Standard SQL transfers everywhere. Indian companies mostly use MySQL, PostgreSQL or SQL Server; the differences in interviews are minor (LIMIT vs TOP, date functions). Mention the dialect in the job description once, and note you adapt quickly.

Are SQL questions asked in non-technical roles?

Yes - analyst, product, marketing operations and even some finance roles in India now include a basic SQL round: one join, one GROUP BY. The bar is lower, but zero preparation still fails it.

How many SQL questions should I prepare?

Quality over count: around 40 patterns covering joins, aggregation, window functions and subqueries handle most rounds. Ten patterns written flawlessly beat a hundred skimmed.

What if I blank on a query in the interview?

Narrate your approach before writing: the tables you need, the join keys, the filter, the grouping. Interviewers routinely rescue candidates who show a correct plan, and writing silently in panic is what actually fails you.

Sources

Question patterns reflect current Indian tech and analytics hiring practice and the sets in our interview question bank. Syntax follows the SQL standard; verify dialect-specific details against your target company's stack.

Found this useful? Send it on.

WhatsAppLinkedIn

Keep reading