
SQL remains one of the most sought-after technical skills in the software industry. Whether you’re applying for roles in software development, data analysis, business intelligence, testing, cloud engineering, or database administration, SQL knowledge is often evaluated during interviews.
Recruiters use SQL questions to assess more than just query-writing abilities. They want to determine whether candidates can think logically, understand data relationships, troubleshoot problems, and work efficiently with databases.
This guide is designed for:
- Students preparing for campus placements
- Fresh graduates attending their first technical interviews
- Working professionals switching careers
- Software engineers revising database concepts
- Data analysts and business intelligence aspirants
By the end of this guide, you’ll understand the most commonly asked SQL interview questions, learn practical examples, and gain insights into what hiring managers actually expect from candidates.
Quick Overview Table
| Section | Topics Covered |
|---|---|
| Beginner Questions | SQL basics, commands, keys |
| Intermediate Questions | Joins, Group By, Aggregate Functions |
| Advanced Questions | Window Functions, CTEs, Optimization |
| Scenario Questions | Real interview problems |
| Recruiter Tips | How interviewers evaluate answers |
| Common Mistakes | Errors candidates often make |
| FAQs | Popular SQL interview queries |
| Career Advice | Preparation strategy and study plan |
What Are SQL Interview Questions?
SQL interview questions are technical questions used by employers to evaluate a candidate’s ability to retrieve, manipulate, analyze, and manage data stored in relational databases.
These questions typically cover:
- SQL syntax
- Database concepts
- Query writing
- Joins
- Aggregate functions
- Subqueries
- Window functions
- Query optimization
- Real-world problem solving
Why SQL Skills Matter in Interviews
SQL is used across multiple domains.
| Role | SQL Usage |
|---|---|
| Software Engineer | Backend database operations |
| Data Analyst | Data extraction and reporting |
| QA Engineer | Database validation |
| Business Analyst | Data insights |
| Database Administrator | Database maintenance |
| Data Scientist | Data preprocessing |
| Cloud Engineer | Working with managed databases |
Recruiters often consider SQL a foundational skill because databases power almost every modern application.
SQL Concepts You Should Know Before Interviews
Before jumping into interview questions, ensure you understand these topics.
Essential SQL Topics Checklist
☑ Database and Table
☑ Primary Key
☑ Foreign Key
☑ Constraints
☑ CRUD Operations
☑ Joins
☑ Aggregate Functions
☑ Group By
☑ Having Clause
☑ Subqueries
☑ Common Table Expressions (CTEs)
☑ Window Functions
☑ Indexes
☑ Transactions
☑ Views
☑ Stored Procedures
☑ Query Optimization
Beginner SQL Interview Questions
1. What is SQL?
Answer
SQL stands for Structured Query Language.
It is a standard programming language used to communicate with relational databases.
SQL allows users to:
- Store data
- Retrieve data
- Update records
- Delete records
- Create database objects
Example
SELECT * FROM Employees;This query retrieves all records from the Employees table.
Recruiter Insight
Interviewers expect candidates to explain SQL in simple terms rather than just expanding the acronym.
A good answer demonstrates an understanding of why SQL is important.
2. What are the different types of SQL commands?
Answer
SQL commands are categorized into five groups.
| Type | Purpose |
|---|---|
| DDL | Defines database structure |
| DML | Manipulates data |
| DQL | Retrieves data |
| DCL | Controls permissions |
| TCL | Manages transactions |
DDL Commands
CREATE
ALTER
DROP
TRUNCATEDML Commands
INSERT
UPDATE
DELETEDQL Commands
SELECTDCL Commands
GRANT
REVOKETCL Commands
COMMIT
ROLLBACK
SAVEPOINTRecruiter Tip
Candidates often forget DCL and TCL commands.
Remembering all five categories creates a strong first impression.
3. What is the difference between DELETE, DROP, and TRUNCATE?
Answer
| Feature | DELETE | TRUNCATE | DROP |
|---|---|---|---|
| Removes Data | Yes | Yes | Yes |
| Removes Table Structure | No | No | Yes |
| WHERE Clause Allowed | Yes | No | No |
| Rollback Possible | Yes | Usually No | No |
| Faster Operation | No | Yes | Yes |
Example
Delete selected rows
DELETE FROM Employees
WHERE EmployeeID=100;Delete all rows
TRUNCATE TABLE Employees;Delete complete table
DROP TABLE Employees;Interviewer’s Perspective
This is one of the most frequently asked SQL questions.
Interviewers are looking for conceptual understanding rather than memorized definitions.
4. What is a Primary Key?
Answer
A primary key uniquely identifies each record in a table.
Characteristics:
- Must contain unique values
- Cannot contain NULL values
- Only one primary key is allowed per table
Example
CREATE TABLE Employee(
EmployeeID INT PRIMARY KEY,
Name VARCHAR(50)
);5. What is a Foreign Key?
Answer
A foreign key establishes a relationship between two tables.
It ensures referential integrity.
Example
Department Table
DepartmentID
DepartmentNameEmployee Table
EmployeeID
DepartmentIDEmployee.DepartmentID references Department.DepartmentID
6. Difference Between Primary Key and Foreign Key
| Feature | Primary Key | Foreign Key |
|---|---|---|
| Uniqueness | Unique | Can repeat |
| Null Values | Not Allowed | Allowed |
| Purpose | Identifies records | Creates relationships |
| Quantity | One per table | Multiple possible |
7. What are Constraints in SQL?
Constraints help maintain data accuracy.
Common constraints include:
NOT NULL
Name VARCHAR(100) NOT NULLUNIQUE
Email VARCHAR(100) UNIQUECHECK
Age INT CHECK(Age>=18)DEFAULT
Country VARCHAR(50)
DEFAULT 'India'8. What is the Difference Between CHAR and VARCHAR?
| Feature | CHAR | VARCHAR |
|---|---|---|
| Length | Fixed | Variable |
| Storage | More | Less |
| Performance | Slightly Faster | Flexible |
| Example | CHAR(10) | VARCHAR(10) |
Example
Name CHAR(20)
Address VARCHAR(200)9. What is a NULL Value?
NULL means data is missing, unknown, or not available.
It is different from:
- Zero
- Empty String
- Space Character
Example
SELECT *
FROM Employees
WHERE Salary IS NULL;10. What is the Difference Between WHERE and HAVING?
| WHERE | HAVING |
|---|---|
| Filters rows | Filters groups |
| Used before Group By | Used after Group By |
| Cannot use aggregate functions | Supports aggregate functions |
Example
SELECT DepartmentID,
COUNT(*)
FROM Employees
GROUP BY DepartmentID
HAVING COUNT(*)>5;SQL Interview Questions for Freshers (Most Frequently Asked)
Q1. Which command retrieves data from a database?
Answer
SELECT
Q2. Which key uniquely identifies records?
Answer
Primary Key
Q3. Which clause is used for sorting?
Answer
ORDER BY
Q4. Which operator searches patterns?
Answer
LIKE
Example
SELECT *
FROM Employees
WHERE Name LIKE 'A%';This returns employees whose names start with A.
Recruiter & Hiring Manager Insights
During interviews for fresher roles, recruiters usually focus on:
- Database fundamentals
- Basic query writing
- Understanding relationships between tables
- Ability to explain concepts clearly
Candidates who explain concepts with examples often perform better than those who only provide textbook definitions.
For example, instead of saying:
“A foreign key maintains referential integrity.”
Try saying:
“If an employee belongs to a department, the DepartmentID in the Employee table should exist in the Department table. A foreign key ensures invalid department IDs cannot be inserted.”
This approach demonstrates practical understanding and leaves a stronger impression during technical discussions.
Intermediate & Advanced SQL Interview Questions
This section covers the SQL concepts most commonly evaluated in technical interviews for Software Engineers, Data Analysts, QA Engineers, Database Developers, and Business Intelligence professionals.
Many companies expect candidates to write queries on a whiteboard, coding platform, or shared editor. Understanding why a query works is often more important than memorizing syntax.
SQL Joins Interview Questions
Joins are among the most frequently asked SQL interview topics because they demonstrate a candidate’s understanding of relationships between tables.
Assume we have two tables.
Employees Table
| EmployeeID | EmployeeName | DepartmentID |
|---|---|---|
| 101 | Rahul | 1 |
| 102 | Priya | 2 |
| 103 | Amit | 3 |
| 104 | Neha | NULL |
Departments Table
| DepartmentID | DepartmentName |
|---|---|
| 1 | HR |
| 2 | IT |
| 4 | Finance |
11. What is an INNER JOIN?
Answer
An INNER JOIN returns only the records that have matching values in both tables.
Example
SELECT e.EmployeeName,
d.DepartmentName
FROM Employees e
INNER JOIN Departments d
ON e.DepartmentID=d.DepartmentID;Output
| EmployeeName | DepartmentName |
|---|---|
| Rahul | HR |
| Priya | IT |
Recruiter Insight
Many candidates know the syntax but fail to explain the result.
Interviewers want to hear:
“INNER JOIN returns only common records from both tables.”
12. What is a LEFT JOIN?
Answer
A LEFT JOIN returns all records from the left table and matching records from the right table.
If no match exists, NULL values are returned.
Example
SELECT e.EmployeeName,
d.DepartmentName
FROM Employees e
LEFT JOIN Departments d
ON e.DepartmentID=d.DepartmentID;Output
| EmployeeName | DepartmentName |
|---|---|
| Rahul | HR |
| Priya | IT |
| Amit | NULL |
| Neha | NULL |
13. What is a RIGHT JOIN?
Answer
A RIGHT JOIN returns all records from the right table.
Unmatched records from the left table appear as NULL.
Example
SELECT e.EmployeeName,
d.DepartmentName
FROM Employees e
RIGHT JOIN Departments d
ON e.DepartmentID=d.DepartmentID;Output
| EmployeeName | DepartmentName |
|---|---|
| Rahul | HR |
| Priya | IT |
| NULL | Finance |
14. What is a FULL OUTER JOIN?
Answer
A FULL OUTER JOIN returns all records from both tables.
Matched rows are combined.
Unmatched rows contain NULL values.
Example
SELECT *
FROM Employees
FULL OUTER JOIN Departments
ON Employees.DepartmentID=
Departments.DepartmentID;15. What is a SELF JOIN?
Answer
A SELF JOIN joins a table with itself.
It is commonly used when employees report to managers stored in the same table.
Employee Table
| EmployeeID | Name | ManagerID |
|---|---|---|
| 1 | John | NULL |
| 2 | David | 1 |
| 3 | Sarah | 1 |
Query
SELECT E.Name Employee,
M.Name Manager
FROM Employee E
LEFT JOIN Employee M
ON E.ManagerID=M.EmployeeID;16. What is a CROSS JOIN?
Answer
A CROSS JOIN returns every possible combination of rows.
Example
SELECT *
FROM Employees
CROSS JOIN Departments;If Employees contain four rows and Departments contain three rows, the output will contain twelve rows.
Aggregate Function SQL Interview Questions
Aggregate functions summarize data.
17. What are Aggregate Functions?
Common aggregate functions include:
| Function | Purpose |
|---|---|
| COUNT() | Counts rows |
| SUM() | Adds values |
| AVG() | Average |
| MAX() | Largest value |
| MIN() | Smallest value |
18. Difference Between COUNT(*) and COUNT(column_name)
COUNT(*)
Counts all rows.
COUNT(Salary)
Counts only non-null salary values.
Example
SELECT COUNT(*)
FROM Employees;SELECT COUNT(Salary)
FROM Employees;Recruiter Tip
This is a surprisingly common interview question.
Many candidates incorrectly assume both produce identical results.
19. Find Highest Salary
SELECT MAX(Salary)
FROM Employees;20. Find Average Salary
SELECT AVG(Salary)
FROM Employees;21. Find Total Salary Expense
SELECT SUM(Salary)
FROM Employees;GROUP BY and HAVING Questions
22. What is GROUP BY?
GROUP BY groups rows having similar values.
Example
SELECT DepartmentID,
COUNT(*)
FROM Employees
GROUP BY DepartmentID;Result
| DepartmentID | Employee Count |
|---|---|
| 1 | 5 |
| 2 | 3 |
| 3 | 7 |
23. Difference Between WHERE and HAVING
| WHERE | HAVING |
|---|---|
| Filters records | Filters groups |
| Before grouping | After grouping |
| Cannot use aggregates | Supports aggregates |
Example
Departments having more than five employees.
SELECT DepartmentID,
COUNT(*)
FROM Employees
GROUP BY DepartmentID
HAVING COUNT(*)>5;Subquery Interview Questions
Subqueries are often asked in interviews because they test logical thinking.
24. What is a Subquery?
A subquery is a query written inside another query.
25. Find Employees Earning Above Average Salary
SELECT *
FROM Employees
WHERE Salary >
(
SELECT AVG(Salary)
FROM Employees
);26. Difference Between Subquery and JOIN
| Subquery | JOIN |
|---|---|
| Nested query | Combines tables |
| Easier for simple logic | Faster in many scenarios |
| Less readable for complex cases | More maintainable |
Hiring Manager Perspective
Experienced candidates should understand when joins are preferable over deeply nested subqueries.
EXISTS and IN SQL Interview Questions
27. Difference Between EXISTS and IN
IN
SELECT *
FROM Employees
WHERE DepartmentID IN
(
SELECT DepartmentID
FROM Departments
);EXISTS
SELECT *
FROM Employees E
WHERE EXISTS
(
SELECT *
FROM Departments D
WHERE E.DepartmentID=
D.DepartmentID
);Comparison
| EXISTS | IN |
|---|---|
| Faster for large datasets | Better for smaller lists |
| Stops after first match | Scans complete set |
| Preferred in complex queries | Easier syntax |
Window Function SQL Interview Questions
Window functions are increasingly asked in interviews for data engineering and analytics roles.
28. What are Window Functions?
Window functions perform calculations across related rows while preserving individual row information.
29. ROW_NUMBER()
Assigns unique sequence numbers.
SELECT Name,
Salary,
ROW_NUMBER()
OVER(
ORDER BY Salary DESC
)
AS RankNo
FROM Employees;30. RANK()
Employees with equal salary receive the same rank.
SELECT Name,
Salary,
RANK()
OVER(
ORDER BY Salary DESC
)
AS RankNo
FROM Employees;31. DENSE_RANK()
Ranks remain consecutive.
Example
| Salary | Rank | Dense Rank |
|---|---|---|
| 90000 | 1 | 1 |
| 90000 | 1 | 1 |
| 85000 | 3 | 2 |
| 70000 | 4 | 3 |
32. Difference Between ROW_NUMBER(), RANK(), and DENSE_RANK()
| Function | Duplicate Values | Gap in Ranking |
|---|---|---|
| ROW_NUMBER() | No | No |
| RANK() | Yes | Yes |
| DENSE_RANK() | Yes | No |
Scenario-Based SQL Interview Questions
These questions are popular among product-based companies.
33. Find the Second Highest Salary
Method 1
SELECT MAX(Salary)
FROM Employees
WHERE Salary <
(
SELECT MAX(Salary)
FROM Employees
);Method 2
SELECT Salary
FROM
(
SELECT Salary,
DENSE_RANK()
OVER(
ORDER BY Salary DESC
)
AS RankNo
FROM Employees
)
WHERE RankNo=2;34. Find Duplicate Records
SELECT Email,
COUNT(*)
FROM Users
GROUP BY Email
HAVING COUNT(*)>1;35. Delete Duplicate Records
WITH CTE AS
(
SELECT *,
ROW_NUMBER()
OVER(
PARTITION BY Email
ORDER BY ID
)
RN
FROM Users
)
DELETE
FROM CTE
WHERE RN>1;36. Find Employees Without Departments
SELECT *
FROM Employees E
LEFT JOIN Departments D
ON E.DepartmentID=
D.DepartmentID
WHERE D.DepartmentID IS NULL;Query Writing Exercises
Exercise 1
Find employees whose salary is greater than ₹50,000.
SELECT *
FROM Employees
WHERE Salary>50000;Exercise 2
Display employees sorted by salary in descending order.
SELECT *
FROM Employees
ORDER BY Salary DESC;Exercise 3
Count employees department-wise.
SELECT DepartmentID,
COUNT(*)
FROM Employees
GROUP BY DepartmentID;Recruiter & Career Coach Tips
How Interviewers Evaluate SQL Candidates
Interviewers generally assess five important skills.
1. Conceptual Understanding
Can the candidate explain joins and keys without memorized definitions?
2. Query Writing Ability
Can they write syntactically correct SQL queries?
3. Problem Solving
Can they solve business-related scenarios?
4. Optimization Awareness
Do they understand indexes and efficient query writing?
5. Communication Skills
Can they explain their thought process clearly?
Preparation Strategy for SQL Interview Questions
Week 1
Study SQL basics.
Week 2
Practice joins and aggregate functions.
Week 3
Learn subqueries and window functions.
Week 4
Solve interview problems on datasets.
Common SQL Interview Mistakes to Avoid
Mistake 1
Using = instead of IS NULL
Incorrect
WHERE Salary = NULLCorrect
WHERE Salary IS NULLMistake 2
Forgetting GROUP BY columns.
Mistake 3
Confusing LEFT JOIN and INNER JOIN.
Mistake 4
Ignoring duplicate records.
Mistake 5
Not explaining assumptions while solving problems.
SQL Interview Questions Preparation Checklist
Preparing for SQL interviews is not just about reading theory. Employers expect candidates to demonstrate practical query-writing skills and explain their thought process clearly.
□ Revise SQL fundamentals
□ Understand Primary Key and Foreign Key concepts
□ Practice CRUD operations
□ Learn all types of joins
□ Master Aggregate Functions
□ Understand GROUP BY and HAVING
□ Practice Subqueries
□ Learn Window Functions
□ Solve Second Highest Salary problems
□ Practice duplicate record questions
□ Understand indexes and query optimization
□ Attempt mock interviews
□ Explain solutions verbally
□ Practice on sample datasets
□ Review common interview mistakes
Join Career Rise Hub Community
| Join Telegram Channel | Click Here |
| Follow Us On LinkedIn | Click Here |
| Follow Us On Instagram | Click Here |
Check Current Job Openings: Click here
People Also Ask about SQL Interview Questions
These are common questions candidates search before SQL interviews.
1. Is SQL enough to get a job?
SQL alone may not be sufficient for software engineering roles, but it is often enough for entry-level Data Analyst, Reporting Analyst, and Business Intelligence positions when combined with Excel and basic visualization skills.
2. Which SQL topics are most important for interviews?
The most frequently asked SQL topics include:
- Joins
- Aggregate Functions
- GROUP BY
- HAVING
- Subqueries
- Window Functions
- Constraints
- Indexes
- Transactions
3. How many SQL questions should I practice before an interview?
Practicing around 75–100 quality SQL questions covering beginner, intermediate, and advanced concepts is usually adequate for most technical interviews.
4. Are SQL questions asked in software engineering interviews?
Yes.
Many companies ask SQL questions for backend development, testing, cloud engineering, and full-stack development roles.
5. Which database should I use for practice?
Popular options include:
- MySQL
- PostgreSQL
- SQL Server
- Oracle Database
- SQLite
MySQL and PostgreSQL are excellent choices for beginners.
6. Is SQL difficult for freshers?
No.
SQL is generally easier to learn compared to many programming languages because it uses simple English-like statements.
7. What are scenario-based SQL questions?
These questions require candidates to solve business problems using SQL queries.
Examples include:
- Finding duplicate records
- Retrieving the second highest salary
- Identifying missing relationships
- Calculating running totals
8. How can I improve SQL query writing speed?
Consistent practice on sample datasets and solving timed exercises can significantly improve query-writing speed and confidence.
Frequently Asked Questions
1. What are the top SQL interview questions for freshers?
Common questions include:
- What is SQL?
- What is a Primary Key?
- Difference between DELETE and TRUNCATE
- Types of joins
- Aggregate functions
- GROUP BY vs HAVING
2. Which SQL query is asked most frequently?
Finding the second highest salary is one of the most commonly asked SQL interview questions.
3. What is the difference between WHERE and HAVING?
WHERE filters individual rows before grouping, whereas HAVING filters grouped records after aggregation.
4. Why are joins important in SQL interviews?
Joins demonstrate your understanding of relationships between tables and your ability to combine data from multiple sources.
5. What are window functions?
Window functions perform calculations across related rows without collapsing the result set.
Examples include:
- ROW_NUMBER()
- RANK()
- DENSE_RANK()
6. Are SQL interview questions difficult?
Difficulty depends on the role and experience level.
Freshers are usually asked basic concepts, while experienced professionals may encounter optimization and performance-related questions.
7. How much SQL should a software engineer know?
Software engineers should be comfortable with:
- Joins
- Indexes
- Transactions
- Stored Procedures
- Query optimization
- Window functions
8. Can I learn SQL in one month?
Yes.
With regular practice, most candidates can build a strong SQL foundation within four weeks.
9. Do companies ask SQL coding questions?
Yes.
Many organizations provide datasets and ask candidates to write queries during technical assessments.
10. What is the best way to prepare for SQL interviews?
A balanced preparation strategy should include:
- Concept revision
- Query writing
- Mock interviews
- Scenario-based problem solving
Recruiter Recommendations for SQL Interviews
Based on feedback from hiring managers and technical interviewers, candidates who perform well usually follow these practices:
Explain Your Approach
Instead of immediately writing a query, briefly describe your thought process.
Example:
“First, I will identify the table relationships, then decide whether a join or subquery is more suitable.”
Clarify Assumptions
If interview requirements are unclear, ask questions.
Examples:
- Are duplicate salaries possible?
- Should NULL values be included?
- Do we need distinct records?
Focus on Readability
Use aliases and proper indentation.
Poorly formatted queries can create a negative impression.
Discuss Optimization
Experienced candidates should mention:
- Index usage
- Avoiding unnecessary subqueries
- Reducing full table scans
Conclusion
Final Thoughts
SQL remains one of the most valuable technical skills for students, fresh graduates, software engineers, data analysts, and career switchers.
Employers continue to evaluate SQL proficiency because it reflects logical thinking, problem-solving ability, and practical database knowledge.
For interview success, focus on understanding concepts rather than memorizing answers. Practice writing queries regularly, solve real-world scenarios, and explain your solutions confidently.
Candidates who combine strong SQL fundamentals with communication skills often stand out during technical interviews.
Call to Action
Looking to improve your placement preparation and interview skills?
Explore more career resources, interview guides, resume templates, and placement preparation articles on CareerRiseHub.com to accelerate your job search journey.

