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.
Showing 26 of 26 questions
- 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β¦
- 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';
- 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β¦
- 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β¦
- 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β¦
- 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.
- 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β¦
- 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 ββ¦
- 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β¦
- 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.
- 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β¦
- 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β¦
- 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β¦
- 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,β¦
- 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β¦
- 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β¦
- 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β¦
- 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β¦
- 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_β¦
- 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β¦
- 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β¦
- 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,β¦
- 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β¦
- 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β¦
- 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β¦
- 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β¦
// Continue exploring
BDD / Cucumber
Gherkin syntax, feature files, step definitions, scenario outlines, hooks, tags, anti-patterns.
JIRA
Bug lifecycle, JQL, workflows, test management (Xray/Zephyr), Agile boards.
Framework design
POM, hybrid/data-driven/keyword-driven frameworks, folder structure, config, reporting, scaling.