20 questions · Updated June 2026

Top SQL Interview Questions and Answers (2026)

SQL is the most tested language in technical interviews — even at companies that don't list it on the JD. These questions cover what actually shows up.

Book a free demo
  1. Q01.Difference between WHERE and HAVING?

    WHERE filters rows before grouping. HAVING filters groups after aggregation.

  2. Q02.What are the main JOIN types?

    INNER, LEFT, RIGHT, FULL OUTER and CROSS. INNER keeps matches; LEFT keeps everything from the left table even without matches.

  3. Q03.What is a primary key?

    A column or combination of columns that uniquely identifies each row and cannot be NULL.

  4. Q04.Difference between DELETE, TRUNCATE and DROP?

    DELETE removes rows (logged, can be rolled back). TRUNCATE removes all rows quickly without per-row logging. DROP removes the table entirely.

  5. Q05.What is normalization?

    The process of structuring tables to reduce redundancy and update anomalies. The common targets are 1NF, 2NF and 3NF.

  6. Q06.What is an index?

    A separate data structure that speeds up lookups on indexed columns, at the cost of slower writes and extra storage.

  7. Q07.What's the difference between UNION and UNION ALL?

    UNION removes duplicates; UNION ALL keeps them and is faster.

  8. Q08.What is a view?

    A saved query you can SELECT from like a table. Useful for encapsulating complex logic or restricting columns visible to a role.

  9. Q09.What does GROUP BY do?

    It collapses rows that share values in the grouped columns so aggregates (SUM, COUNT, AVG) can be computed per group.

  10. Q10.Difference between CHAR and VARCHAR?

    CHAR is fixed-length and padded. VARCHAR is variable-length. Use VARCHAR unless you truly need fixed-width.

  11. Q11.What are window functions?

    Functions like ROW_NUMBER, RANK, SUM OVER that compute across a set of rows defined by a window without collapsing them.

  12. Q12.What is a CTE?

    A Common Table Expression — a named temporary result set defined with WITH that improves readability and supports recursion.

  13. Q13.What is the difference between a stored procedure and a function?

    Procedures perform actions and may not return values. Functions return a value and can be used inside SELECT statements.

  14. Q14.What is a transaction?

    A unit of work that succeeds or fails as a whole. Bound by ACID properties — atomicity, consistency, isolation, durability.

  15. Q15.Explain isolation levels.

    READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ and SERIALIZABLE — each trades concurrency for consistency. PostgreSQL defaults to READ COMMITTED.

  16. Q16.What's the N+1 query problem?

    Loading one row then issuing one query per associated child — extremely slow. Fix with JOINs or batch loading in your ORM.

  17. Q17.What is a composite key?

    A primary key made up of multiple columns together.

  18. Q18.How do you find duplicate rows?

    GROUP BY the columns that should be unique and add HAVING COUNT(*) > 1.

  19. Q19.What is denormalization?

    Deliberately adding redundancy to a schema to optimise reads at the cost of writes — common in analytics and read-heavy systems.

  20. Q20.When would you use NoSQL over SQL?

    When data is naturally hierarchical or schema-less, write volume is huge, or you need horizontal scale beyond a single primary. Otherwise SQL's consistency and tooling usually wins.

Interview prep support

Get 1:1 prep on SQL

Our mentors will reach out with a personalised prep plan, mock interview slots and target-company question banks.