SQL interview questions for QA engineers

// 26 QUESTIONS Β· UPDATED MAY 2026

SQL interview questions scoped for QA engineers and SDETs. Covers SELECT, JOINs, GROUP BY/HAVING, subqueries, CTEs, window functions, and practical patterns for validating database state after a test, finding duplicate or orphaned records, and comparing expected vs actual result sets.

Level

Showing 26 of 26 questions

  1. Why do QA engineers need SQL skills?Junior

    SQL lets QA engineers query the database directly to validate that the application stored data correctly, find test data, verify state af…

  2. Write a SELECT query to find all orders placed by a specific customer that are in 'pending' status.Junior

    SELECT * FROM orders WHERE customer_id = 42 AND status = 'pending';

  3. What is the difference between INNER JOIN and LEFT JOIN, and when would you use each in a QA context?Junior

    INNER JOIN returns only rows that match in both tables. LEFT JOIN returns all rows from the left table, with NULLs where there is no matc…

  4. How do GROUP BY and HAVING work, and how would you use them to find duplicate records?Junior

    GROUP BY collapses rows into groups by one or more columns and lets you apply aggregate functions. HAVING filters those groups β€” like WHE…

  5. Which aggregate functions do QA engineers use most, and what does each do?Junior

    COUNT, SUM, AVG, MIN, MAX β€” used to summarise groups of rows. COUNT(*) counts all rows; COUNT(col) skips NULLs. SUM/AVG/MIN/MAX work on n…

  6. Write a query to find duplicate records in a users table based on email address.Junior

    Use GROUP BY email HAVING COUNT(*) > 1 to find duplicated emails, then join back to get the full rows.

  7. How do you find rows with NULL values in a specific column, and why can't you use = NULL?Junior

    Use IS NULL (not = NULL). NULL represents the absence of a value; SQL's equality operator cannot compare to 'unknown', so = NULL always e…

  8. How would you use SQL to compare an expected result set against what is actually in the database?Junior

    Create or populate an 'expected' table, then FULL OUTER JOIN it against the actual table and filter for rows where either side is NULL —…

  9. How do you validate database state after an automated test runs?Mid

    After the action under test, query the relevant tables directly and assert that rows exist with expected values, counts, and relationship…

  10. Write a query to find orphaned records β€” rows in a child table with no matching parent.Mid

    LEFT JOIN the child table to the parent on the foreign key, then WHERE parent.id IS NULL filters to rows with no match.

  11. What is a subquery and when would you use one instead of a JOIN in QA work?Mid

    A subquery is a SELECT nested inside another query. Use it when the inner result is a single value or a list that filters the outer query…

  12. What is the difference between EXISTS and IN in SQL, and when does it matter for QA queries?Mid

    IN evaluates a full list of values; EXISTS short-circuits as soon as one match is found and is safer when the subquery result might conta…

  13. When would you use UNION vs UNION ALL in a QA context?Mid

    UNION removes duplicate rows (extra sort/distinct pass); UNION ALL keeps all rows including duplicates and is faster. Use UNION ALL unles…

  14. How do you use a CASE statement in SQL, and give a QA example.Mid

    CASE is SQL's if/else β€” it maps values or conditions to output values in a SELECT, useful for bucketing data, transforming status codes,…

  15. How are SQL transactions used in automated testing, and what is the benefit of rolling back after each test?Mid

    Wrapping each test in a transaction and rolling it back on teardown is the fastest and cleanest way to reset DB state β€” the data never pe…

  16. What is a CTE (Common Table Expression) and how does it make complex QA queries more readable?Mid

    A CTE is a named temporary result set defined with WITH … AS (…) at the top of a query. It makes multi-step queries readable by letting y…

  17. How do you verify referential integrity using SQL after a data migration?Mid

    Run LEFT JOIN checks for every foreign key relationship to find child rows with no matching parent, and compare row counts against the so…

  18. What does EXPLAIN (or EXPLAIN ANALYZE) do, and why might a QA engineer use it?Mid

    EXPLAIN shows the query execution plan β€” how the database will fetch and join rows. EXPLAIN ANALYZE actually runs the query and shows rea…

  19. What are window functions and give a QA example using ROW_NUMBER or RANK.Senior

    Window functions compute a value across a set of rows related to the current row (a 'window'), without collapsing them into a group. ROW_…

  20. What strategies do you use for seeding test data with SQL, and how do you avoid test pollution?Senior

    Use deterministic IDs or known-prefix naming, run seeds inside a transaction you can roll back, and scope test data to each test with a u…

  21. How do you verify that test teardown actually cleaned up all test data?Senior

    After teardown runs, query each table using the test-data identifier (ID range, email prefix, run ID) and assert COUNT(*) = 0. Automate t…

  22. When would a QA engineer care about database indexes, and how do indexes affect test execution speed?Senior

    Indexes make queries on large tables fast by avoiding full table scans. QA engineers care when test-data setup/teardown queries are slow,…

  23. How would you use stored procedures or database functions in a QA context?Senior

    Stored procedures encapsulate reusable DB logic β€” useful in QA for seeding complex test data in one call, running post-test cleanup, or w…

  24. How do you use SQL to compare data across environments (e.g., staging vs production)?Senior

    Use database links, linked servers, or export-to-CSV + staging import to run EXCEPT or FULL OUTER JOIN queries that show rows that differ…

  25. Which SQL string functions are most useful in QA work, and give an example of each.Mid

    TRIM, UPPER/LOWER, LIKE, CONCAT, SUBSTRING, LENGTH, and REPLACE β€” used to normalise data before comparison, validate format, and find mal…

  26. How do you use date and time functions in SQL for QA validation?Mid

    Date functions let you query records relative to 'now', calculate elapsed time, validate that timestamps fall within expected windows, an…