Database Administrator Top 20+ Basic SQL Interview Questions and Answers
Prepare for your next data or database-related job interview with these essential Basic SQL interview questions and answers. Covers queries, joins, subqueries, indexing, and more. Curated by Interview Chamber.

Basic DBA SQL Interview Questions and Answers
Whether you're a beginner or preparing for an entry-level data role, mastering SQL is essential for database management and analysis. Below are the most common SQL interview questions and answers categorized by topic, perfect for revision and practice.
1. What is SQL, and Why is It Important in Data Analysis?
Answer:
SQL (Structured Query Language) is used to interact with and manipulate relational databases. It is vital for data analysis because it allows efficient data retrieval, filtering, aggregation, and transformation. SQL helps analysts extract insights, prepare reports, and make informed decisions.
2. Difference Between SQL and MySQL
Answer:
-
SQL is a standard language used to manage relational databases.
-
MySQL is a specific database management system (DBMS) that implements SQL.
-
SQL is the language; MySQL is a software tool that uses it.
3. Types of SQL Commands
Answer:
-
DML (Data Manipulation Language):
SELECT
,INSERT
,UPDATE
,DELETE
-
DDL (Data Definition Language):
CREATE
,ALTER
,DROP
,TRUNCATE
-
DCL (Data Control Language):
GRANT
,REVOKE
-
TCL (Transaction Control Language):
COMMIT
,ROLLBACK
,SAVEPOINT
4. Difference Between WHERE and HAVING Clauses
Answer:
-
WHERE
filters rows before aggregation. -
HAVING
filters aggregated data.
Example:
5. Retrieve All Records from a Table
Answer:
6. Top 5 Highest Revenue Taxpayers
Answer:
7. SQL JOINS: Types and Differences
Answer:
-
INNER JOIN: Returns rows with matching values in both tables.
-
LEFT JOIN: Returns all rows from the left table and matching ones from the right.
-
RIGHT JOIN: Returns all rows from the right table and matching ones from the left.
-
FULL JOIN: Returns all rows when there’s a match in either table.
Example:
8. Join Two Tables Using SQL
Tables:
-
taxpayer_details (taxpayer_id, name, address)
-
tax_payments (taxpayer_id, amount_paid, payment_date)
Query:
9. SELF JOIN vs CROSS JOIN
Answer:
-
SELF JOIN: Joins a table to itself.
-
CROSS JOIN: Produces the Cartesian product.
10. Difference Between UNION and UNION ALL
Answer:
-
UNION
: Eliminates duplicates. -
UNION ALL
: Includes all results, including duplicates.
Example:
🔹 Data Aggregation & Filtering
11. Total Tax Collected in 2024
12. Find Second Highest Tax Payment
13. SQL Aggregate Functions
-
COUNT()
: Counts rows -
SUM()
: Adds values -
AVG()
: Calculates average -
MIN()
: Minimum value -
MAX()
: Maximum value
14. Count Unique Taxpayers in a City
15. GROUP BY with HAVING Clause
🔹 Advanced SQL (Subqueries, CTEs, Indexing)
16. What Is a Subquery?
A query embedded inside another query.
17. What Is a Common Table Expression (CTE)?
Temporary named result set.
18. What Are Window Functions?
Allow row-wise calculations over a window of rows.
19. DELETE vs TRUNCATE vs DROP
-
DELETE
: Removes specific rows. -
TRUNCATE
: Removes all rows, keeps structure. -
DROP
: Deletes the table structure entirely.
20. What Is an Index in SQL?
An index boosts performance by speeding up queries.
Types:
-
Clustered Index: Orders actual data rows.
-
Non-Clustered Index: Stores pointers to data.
Example:
21. ACID Properties in Transactions
-
Atomicity: All-or-nothing execution.
-
Consistency: Preserves valid data state.
-
Isolation: Transactions are independent.
-
Durability: Changes persist after commit.
Example:
22. What Are Stored Procedures?
Precompiled reusable SQL blocks.
Execute:
23. Primary Key vs Unique Key
Feature | Primary Key | Unique Key |
---|---|---|
Uniqueness | Enforced | Enforced |
NULL Allowed | No | Yes (one NULL) |
Number Allowed | One per table | Multiple |
Purpose | Identify each row | Enforce uniqueness |
Example:
24. How to Optimize Slow SQL Queries
-
Use indexes:
-
Avoid
SELECT *
:
-
Prefer joins over nested subqueries.
-
Use
WHERE
instead ofHAVING
when possible. -
Analyze with
EXPLAIN PLAN
: