SQL Topics
SQL Output-Based Interview Questions
title: SQL Output-Based Interview Questions
In many technical interviews, the interviewer will not ask:
Definitions
Theory
ConceptsInstead, they may show:
Queryand ask:
What Will Be The Output?These questions test:
SQL Understanding
Execution Order
Joins
Grouping
Window Functions
NULL Handling
Logicand are extremely common in:
Placements
Coding Tests
SQL Interviews
Data Analyst InterviewsQuestion 1
Table:
| ID | Name |
|---|---|
| 1 | Rahul |
| 2 | Priya |
Query:
SELECT COUNT(*)
FROM Employees;Output
2Explanation
COUNT(*) counts all rows.
Question 2
Table:
| Salary |
|---|
| --------- |
| 50000 |
| NULL |
| 70000 |
Query:
SELECT COUNT(Salary)
FROM Employees;Output
2Explanation
COUNT(column):
Ignores NULL ValuesQuestion 3
Query:
SELECT COUNT(*)
FROM Employees;Same table.
Output
3Explanation
COUNT(*) includes NULL rows.
Question 4
Table:
| Salary |
|---|
| --------- |
| 50000 |
| 70000 |
| 90000 |
Query:
SELECT AVG(Salary)
FROM Employees;Output
70000Calculation:
(50000+70000+90000)/3Question 5
Table:
| Salary |
|---|
| --------- |
| 50000 |
| NULL |
| 90000 |
Query:
SELECT AVG(Salary)
FROM Employees;Output
70000Explanation
NULL values ignored.
Question 6
Table:
| Name |
|---|
| ------ |
| Rahul |
| Rahul |
| Priya |
Query:
SELECT DISTINCT Name
FROM Employees;Output
Rahul
PriyaQuestion 7
Table:
| Salary |
|---|
| --------- |
| 50000 |
| 70000 |
| 60000 |
Query:
SELECT *
FROM Employees
ORDER BY Salary DESC;Output
70000
60000
50000Question 8
Table:
| ID |
|---|
| ---- |
| 1 |
| 2 |
| 3 |
Query:
SELECT *
FROM Employees
WHERE ID > 2;Output
3Question 9
Table:
| DepartmentID |
|---|
| -------------- |
| 1 |
| 1 |
| 2 |
| 2 |
| 2 |
Query:
SELECT DepartmentID,
COUNT(*)
FROM Employees
GROUP BY DepartmentID;Output
| DepartmentID | Count |
|---|---|
| 1 | 2 |
| 2 | 3 |
Question 10
Table:
| DepartmentID |
|---|
| -------------- |
| 1 |
| 1 |
| 2 |
| 2 |
| 2 |
Query:
SELECT DepartmentID,
COUNT(*)
FROM Employees
GROUP BY DepartmentID
HAVING COUNT(*) > 2;Output
| DepartmentID | Count |
|---|---|
| 2 | 3 |
Question 11
Employees:
| ID | Name |
|---|---|
| 1 | Rahul |
| 2 | Priya |
Departments:
| ID | Department |
|---|---|
| 1 | HR |
| 3 | IT |
Query:
SELECT *
FROM Employees E
INNER JOIN Departments D
ON E.ID = D.ID;Output
| ID | Name | Department |
|---|---|---|
| 1 | Rahul | HR |
Question 12
Same tables.
Query:
SELECT *
FROM Employees E
LEFT JOIN Departments D
ON E.ID = D.ID;Output
| ID | Name | Department |
|---|---|---|
| 1 | Rahul | HR |
| 2 | Priya | NULL |
Question 13
Query:
SELECT NULL = NULL;Output
Unknown / NULLExplanation
NULL is not equal to anything.
Even:
NULL != NULLQuestion 14
Query:
SELECT *
FROM Employees
WHERE Salary = NULL;Output
No RowsCorrect Query
WHERE Salary IS NULLQuestion 15
Table:
| Salary |
|---|
| --------- |
| 80000 |
| 70000 |
| 70000 |
| 60000 |
Query:
SELECT
RANK()
OVER
(
ORDER BY Salary DESC
)
FROM Employees;Output
1
2
2
4Question 16
Same table.
Query:
SELECT
DENSE_RANK()
OVER
(
ORDER BY Salary DESC
)
FROM Employees;Output
1
2
2
3Question 17
Same table.
Query:
SELECT
ROW_NUMBER()
OVER
(
ORDER BY Salary DESC
)
FROM Employees;Output
1
2
3
4Question 18
Table:
| Salary |
|---|
| --------- |
| 100 |
| 200 |
| 300 |
Query:
SELECT
SUM(Salary)
OVER
(
ORDER BY Salary
)
FROM Employees;Output
100
300
600Explanation
Running Total:
100
100+200=300
300+300=600Question 19
Table:
| ID |
|---|
| ---- |
| 1 |
| 2 |
| 3 |
Query:
SELECT TOP 2 *
FROM Employees;Output
1
2(SQL Server)
Question 20
Table:
| Salary |
|---|
| --------- |
| 50000 |
| 60000 |
| 70000 |
Query:
SELECT MAX(Salary)
FROM Employees;Output
70000Question 21
Query:
SELECT MIN(Salary)
FROM Employees;Output
50000Question 22
Query:
SELECT SUM(Salary)
FROM Employees;Output
180000Question 23
Table:
| Name |
|---|
| ------ |
| Rahul |
| Priya |
Query:
SELECT UPPER(Name)
FROM Employees;Output
RAHUL
PRIYAQuestion 24
Query:
SELECT LOWER(Name)
FROM Employees;Output
rahul
priyaQuestion 25
Query:
SELECT LENGTH('SQL');Output
3Question 26
Table:
| ID |
|---|
| ---- |
| 1 |
| 2 |
| 3 |
Query:
SELECT *
FROM Employees
WHERE ID IN (1,3);Output
1
3Question 27
Query:
SELECT *
FROM Employees
WHERE ID BETWEEN 1 AND 2;Output
1
2Question 28
Query:
SELECT *
FROM Employees
WHERE Name LIKE 'R%';Output
RahulQuestion 29
Query:
SELECT *
FROM Employees
WHERE Name LIKE '%l';Output
RahulQuestion 30
Table:
| Salary |
|---|
| --------- |
| 50000 |
| 70000 |
| 90000 |
Query:
SELECT Salary
FROM Employees
ORDER BY Salary DESC
LIMIT 1 OFFSET 1;Output
70000Explanation
Second Highest Salary.
Question 31
Query:
SELECT 10 + NULL;Output
NULLQuestion 32
Query:
SELECT COALESCE(NULL,NULL,100);Output
100Question 33
Query:
SELECT IFNULL(NULL,50);(MySQL)
Output
50Question 34
Query:
SELECT 5 IN (1,2,3,5);Output
TRUEQuestion 35
Query:
SELECT EXISTS
(
SELECT 1
);Output
TRUEQuestion 36
Table:
| Salary |
|---|
| --------- |
| 100 |
| 200 |
| 300 |
Query:
SELECT
AVG(Salary)
OVER()
FROM Employees;Output
200
200
200Question 37
Query:
SELECT CURRENT_DATE;Output
Current DateQuestion 38
Query:
SELECT NOW();Output
Current Date + TimeQuestion 39
Query:
SELECT 10/2;Output
5Question 40
Query:
SELECT MOD(10,3);Output
1Most Asked Output-Based Questions
COUNT(*) vs COUNT(Column)
NULL Handling
JOIN Outputs
GROUP BY Outputs
RANK vs DENSE_RANK
Window Functions
Running Totals
DISTINCT
LIKE
BETWEENInterview Tips
Solve On Paper
Practice predicting outputs without executing queries.
Understand Execution Order
FROM
WHERE
GROUP BY
HAVING
SELECT
ORDER BY
LIMITLearn NULL Behavior
Many interview questions focus on NULL.
Practice Window Functions
Frequently asked in interviews.
Read Queries Carefully
One small condition can change the output completely.
SQL Interview Module Completed ✅
Remaining Folder
Next Topic
SQL Exercises (Beginner) →
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for SQL Output-Based Interview Questions.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this SQL topic.
Search Terms
sql, sql complete guide, sql tutorial, sql notes, complete, guide, interview, questions
Related SQL Topics