How to Use This Guide

These are the SQL interview questions that software testers encounter most frequently during interviews.

Each answer provides a concise explanation suitable for interview revision. For complete explanations, SQL queries, and practical examples, refer to the linked tutorial.

For the complete learning path, begin with the Complete SQL for Testers Guide.

Advertisement

SQL Basics (Q1–7)

Q1. What is SQL?

SQL (Structured Query Language) is used to store, retrieve, update, and manipulate data in relational databases.

Learn more: Basic SQL


Q2. What are DDL, DML, DCL, and TCL?

SQL commands are grouped into categories:

  • DDL – CREATE, ALTER, DROP
  • DML – INSERT, UPDATE, DELETE, SELECT
  • DCL – GRANT, REVOKE
  • TCL – COMMIT, ROLLBACK

Learn more: Basic SQL


Q3. What is the difference between DELETE, TRUNCATE, and DROP?

  • DELETE removes selected rows.
  • TRUNCATE removes all rows from a table.
  • DROP removes the entire table.

Learn more: Basic SQL


Q4. What is the difference between a Primary Key and a Foreign Key?

  • A Primary Key uniquely identifies each record in a table.
  • A Foreign Key references a Primary Key in another table.

Learn more: Basic SQL


Q5. What is the difference between WHERE and HAVING?

  • WHERE filters rows before grouping.
  • HAVING filters grouped results after aggregation.

Learn more: Basic SQL


Q6. What is the difference between CHAR and VARCHAR?

  • CHAR stores fixed-length data.
  • VARCHAR stores variable-length data.

Learn more: Basic SQL


Q7. What is the difference between IS NULL and = NULL?

= NULL does not match NULL values.

Use:

IS NULL

to check for NULL values.

Learn more: SELECT & Filtering


Filtering & Operators (Q8–10)

Q8. What does DISTINCT do?

DISTINCT removes duplicate values and returns only unique records.

Learn more: SELECT & Filtering


Q9. What is the difference between IN and BETWEEN?

  • IN matches values from a specified list.
  • BETWEEN matches values within a specified range.

Learn more: SELECT & Filtering


Q10. What is the LIKE operator?

LIKE performs pattern matching using wildcards:

  • % – Multiple characters
  • _ – Single character

Learn more: SELECT & Filtering


Joins (Q11–14)

Q11. What is a JOIN and why is it used?

A JOIN combines data from multiple related tables.

It is required because normalized databases store related information across separate tables.

Learn more: Joins


Q12. What are the different types of SQL JOINs?

Common JOIN types include:

  • INNER JOIN
  • LEFT JOIN
  • RIGHT JOIN
  • FULL JOIN

Learn more: SQL Joins Compared


Q13. How do you find records that exist in one table but not another?

Use:

  • LEFT JOIN with IS NULL
  • NOT IN
  • NOT EXISTS

Learn more: Joins


Q14. How do you find common records between two tables?

Use:

  • INNER JOIN
  • INTERSECT

Learn more: Joins


Aggregate Functions & Grouping (Q15–17)

Q15. What are aggregate functions?

Common aggregate functions include:

  • COUNT
  • SUM
  • AVG
  • MIN
  • MAX

These are typically used together with GROUP BY.

Learn more: Aggregates & Grouping


Q16. What is the difference between COUNT(*) and COUNT(column)?

  • COUNT(*) counts all rows.
  • COUNT(column) counts only non-NULL values.

Learn more: Aggregates & Grouping


Q17. What does GROUP BY do?

GROUP BY groups rows having the same values so aggregate calculations can be performed.

Learn more: Aggregates & Grouping


Subqueries (Q18–20)

Q18. What is a subquery?

A subquery is a query written inside another SQL query.

It is commonly used for filtering, calculations, and nested data retrieval.

Learn more: Subqueries


Q19. How do you find the second or nth highest salary?

Use a subquery or a window function to identify the required salary ranking.

This is one of the most frequently asked SQL interview questions.

Learn more: Subqueries


Q20. What is the difference between correlated and non-correlated subqueries?

  • A Non-Correlated Subquery executes independently.
  • A Correlated Subquery executes once for each row returned by the outer query.

Learn more: Subqueries


Transactions & Advanced SQL (Q21–23)

Q21. What is a transaction? What are COMMIT and ROLLBACK?

A transaction represents a logical unit of work.

  • COMMIT permanently saves changes.
  • ROLLBACK reverses uncommitted changes.

Learn more: Data Modification


Q22. What are the ACID properties?

The ACID properties are:

  • Atomicity
  • Consistency
  • Isolation
  • Durability

They ensure reliable database transactions.

Learn more: Data Modification


Q23. What is normalization?

Normalization organizes data to reduce redundancy.

Common normal forms include:

  • 1NF
  • 2NF
  • 3NF

Learn more: Advanced SQL & Normalization


Database Testing (Q24–25)

Q24. How do you validate backend data against the UI?

Retrieve the corresponding database record and compare it with the values displayed in the application.

This forms the basis of database testing.

Learn more: Scenario-Based SQL


Q25. How do you verify that a record was inserted successfully?

Execute a SELECT query using the record's key and verify that every field matches the expected values.

Learn more: Scenario-Based SQL


Bonus: Practical Tester Queries

Your practical SQL queries cover several real-world interview scenarios, including:

  • Count bugs raised in the last 7 days.
  • Find users who did not log in today.
  • Count bugs assigned to each developer.
  • Find the highest and lowest bug severity counts.
  • Count passed and failed test cases.

Learn more: Practical SQL Queries


Next Steps

Continue your SQL interview preparation with:

  • Complete SQL for Testers Guide
  • SQL Joins Compared
  • Java for Testers Guide (JDBC)
  • SDET Interview Guide