SQL Interview Questions (2026 Guide for Freshers & Experienced Professionals)

SQL Interview Questions

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

SectionTopics Covered
Beginner QuestionsSQL basics, commands, keys
Intermediate QuestionsJoins, Group By, Aggregate Functions
Advanced QuestionsWindow Functions, CTEs, Optimization
Scenario QuestionsReal interview problems
Recruiter TipsHow interviewers evaluate answers
Common MistakesErrors candidates often make
FAQsPopular SQL interview queries
Career AdvicePreparation 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.

RoleSQL Usage
Software EngineerBackend database operations
Data AnalystData extraction and reporting
QA EngineerDatabase validation
Business AnalystData insights
Database AdministratorDatabase maintenance
Data ScientistData preprocessing
Cloud EngineerWorking 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.

TypePurpose
DDLDefines database structure
DMLManipulates data
DQLRetrieves data
DCLControls permissions
TCLManages transactions

DDL Commands

CREATE

ALTER

DROP

TRUNCATE

DML Commands

INSERT

UPDATE

DELETE

DQL Commands

SELECT

DCL Commands

GRANT

REVOKE

TCL Commands

COMMIT

ROLLBACK

SAVEPOINT

Recruiter 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

FeatureDELETETRUNCATEDROP
Removes DataYesYesYes
Removes Table StructureNoNoYes
WHERE Clause AllowedYesNoNo
Rollback PossibleYesUsually NoNo
Faster OperationNoYesYes

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
DepartmentName

Employee Table

EmployeeID

DepartmentID

Employee.DepartmentID references Department.DepartmentID


6. Difference Between Primary Key and Foreign Key

FeaturePrimary KeyForeign Key
UniquenessUniqueCan repeat
Null ValuesNot AllowedAllowed
PurposeIdentifies recordsCreates relationships
QuantityOne per tableMultiple possible

7. What are Constraints in SQL?

Constraints help maintain data accuracy.

Common constraints include:

NOT NULL

Name VARCHAR(100) NOT NULL

UNIQUE

Email VARCHAR(100) UNIQUE

CHECK

Age INT CHECK(Age>=18)

DEFAULT

Country VARCHAR(50)

DEFAULT 'India'

8. What is the Difference Between CHAR and VARCHAR?

FeatureCHARVARCHAR
LengthFixedVariable
StorageMoreLess
PerformanceSlightly FasterFlexible
ExampleCHAR(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?

WHEREHAVING
Filters rowsFilters groups
Used before Group ByUsed after Group By
Cannot use aggregate functionsSupports 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

EmployeeIDEmployeeNameDepartmentID
101Rahul1
102Priya2
103Amit3
104NehaNULL

Departments Table

DepartmentIDDepartmentName
1HR
2IT
4Finance

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

EmployeeNameDepartmentName
RahulHR
PriyaIT

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

EmployeeNameDepartmentName
RahulHR
PriyaIT
AmitNULL
NehaNULL

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

EmployeeNameDepartmentName
RahulHR
PriyaIT
NULLFinance

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

EmployeeIDNameManagerID
1JohnNULL
2David1
3Sarah1

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:

FunctionPurpose
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

DepartmentIDEmployee Count
15
23
37

23. Difference Between WHERE and HAVING

WHEREHAVING
Filters recordsFilters groups
Before groupingAfter grouping
Cannot use aggregatesSupports 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

SubqueryJOIN
Nested queryCombines tables
Easier for simple logicFaster in many scenarios
Less readable for complex casesMore 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

EXISTSIN
Faster for large datasetsBetter for smaller lists
Stops after first matchScans complete set
Preferred in complex queriesEasier 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

SalaryRankDense Rank
9000011
9000011
8500032
7000043

32. Difference Between ROW_NUMBER(), RANK(), and DENSE_RANK()

FunctionDuplicate ValuesGap in Ranking
ROW_NUMBER()NoNo
RANK()YesYes
DENSE_RANK()YesNo

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 = NULL

Correct

WHERE Salary IS NULL

Mistake 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 ChannelClick Here
Follow Us On LinkedInClick Here
Follow Us On InstagramClick 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.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top