SQL Query Output Questions 2026: 28 Predict-the-Result

What changed in 2026 drives
Mass-recruiter offer letters are flatter for 2026 batch - the 4-5 LPA ASE band has barely budged in three years while inflation eats real wages. Premium tracks (Digital, Pro, Elite, Specialist) are still where the differential lives, and they are entirely test-driven. If you are aiming higher than the default offer, the coding round is not optional pageantry - it is the entire interview.
What I'd actually study for this
- 01Two solid coding-round answers (1 medium-hard DSA each, with edge-case discussion) > five half-baked ones
- 02One real project you can defend end-to-end - file paths, design decisions, and what you would change
- 03One DBMS schema you actually built (not a textbook ER diagram), with at least 3 join-heavy queries written from memory
- 04Three behavioural STAR stories: failure recovered, conflict handled, ownership taken
Where most candidates trip up
The single biggest mistake is treating company-specific guides as primary prep and DSA as secondary. It is the opposite. Mass recruiters use the test as a filter, but premium tracks at every IT services company use coding to allocate offer band. Spend 70% of prep time on DSA + system fundamentals, 20% on company-specific patterns, 10% on HR rehearsal. Reverse that ratio and you collect the default offer.
Editorial commentary by Aditya Sharma · written for PapersAdda · not generated, not aggregated.
Last Updated: June 2026 | Level: Freshers to Mid-Level | Read Time: ~16 min
Query-output questions test whether you can run SQL in your head, the clearest signal of real fluency. Candidates report these dominate data analyst and backend screens. This guide gives 28 queries with the exact result and a precise explanation, noting where engines differ rather than pretending there is one answer. Behaviour reflects ANSI SQL and the major engines; confirm any engine-specific detail on the official docs.
Pair this with SQL Interview Questions 2026 and SQL Joins Interview Questions 2026.
Sample Table Used Throughout
-- sales
| id | region | amount |
|----|--------|--------|
| 1 | East | 100 |
| 2 | East | 200 |
| 3 | West | NULL |
| 4 | West | 150 |
| 5 | NULL | 50 |
Table of Contents
- NULL Logic (Q1 to Q8)
- GROUP BY and Aggregates (Q9 to Q17)
- Filtering and Ordering (Q18 to Q23)
- Joins and Windows (Q24 to Q28)
- Quick Trap Table
- Frequently Asked Questions
NULL Logic
Q1.
SELECT COUNT(*) FROM sales;
SELECT COUNT(amount) FROM sales;
Result: 5 then 4
Why: COUNT(*) counts all rows; COUNT(amount) skips the NULL amount. The most common NULL trap.
Q2.
SELECT 100 + NULL;
Result: NULL
Why: Any arithmetic with NULL yields NULL, not 100.
Q3.
SELECT * FROM sales WHERE amount = NULL;
Result: (no rows)
Why: Nothing equals NULL, even NULL itself. Use IS NULL instead.
Q4.
SELECT * FROM sales WHERE amount IS NULL;
Result: (row 3, West, NULL)
Why: IS NULL is the correct test for missing values.
Q5.
SELECT COALESCE(amount, 0) FROM sales WHERE id = 3;
Result: 0
Why: COALESCE returns the first non-NULL argument, substituting 0 for the NULL amount.
Q6.
SELECT SUM(amount) FROM sales;
Result: 500
Why: SUM ignores NULLs, adding 100 + 200 + 150 + 50.
Q7.
SELECT AVG(amount) FROM sales;
Result: 125
Why: AVG divides the sum (500) by the count of non-NULL amounts (4), not by all 5 rows.
Q8.
SELECT NULL = NULL, NULL IS NULL;
Result: NULL, true
Why: Equality with NULL is unknown (NULL); only IS NULL returns a true boolean.
GROUP BY and Aggregates
Q9.
SELECT region, COUNT(*) FROM sales GROUP BY region;
Result:
East 2
West 2
NULL 1
Why: GROUP BY treats all NULLs as one group, so the NULL region forms its own row.
Q10.
SELECT region, SUM(amount) FROM sales GROUP BY region;
Result:
East 300
West 150
NULL 50
Why: West sums 150 only because its other amount is NULL and ignored.
Q11.
SELECT region, COUNT(amount) FROM sales GROUP BY region;
Result:
East 2
West 1
NULL 1
Why: West has one NULL amount, so COUNT(amount) is 1 there.
Q12.
SELECT region FROM sales GROUP BY region HAVING SUM(amount) > 100;
Result: East
Why: HAVING filters groups after aggregation; only East's sum (300) exceeds 100.
Q13.
SELECT region, MAX(amount), MIN(amount) FROM sales GROUP BY region;
Result:
East 200 100
West 150 150
NULL 50 50
Why: MAX and MIN ignore NULLs within each group.
Q14.
SELECT COUNT(DISTINCT region) FROM sales;
Result: 2
Why: DISTINCT counts unique non-NULL regions (East, West); NULL is excluded by COUNT.
Q15.
SELECT region, COUNT(*) FROM sales GROUP BY region HAVING COUNT(*) = 1;
Result: NULL 1
Why: Only the NULL region group has exactly one row.
Q16.
SELECT SUM(amount) FROM sales WHERE region = 'West';
Result: 150
Why: Only West rows are summed; the NULL amount is ignored.
Q17.
SELECT region, AVG(amount) FROM sales GROUP BY region;
Result:
East 150
West 150
NULL 50
Why: West's AVG is 150 / 1 (the single non-NULL value), not divided by 2.
Filtering and Ordering
Q18.
SELECT * FROM sales WHERE amount > 100 ORDER BY amount DESC;
Result: rows with amount 200 then 150 Why: Filter to amounts over 100 (200, 150), sorted descending. NULL and values under 100 excluded.
Q19.
SELECT region FROM sales WHERE region IN ('East', 'West') GROUP BY region;
Result: East, West
Why: The NULL region fails the IN test and is excluded.
Q20.
SELECT * FROM sales ORDER BY amount;
Result: NULL ordering is engine-dependent Why: Some engines sort NULLs first, others last. The honest answer notes the difference; use NULLS FIRST or NULLS LAST to be explicit.
Q21.
SELECT DISTINCT region FROM sales;
Result: East, West, NULL
Why: DISTINCT keeps one of each distinct value, and NULL counts as a single distinct value here.
Q22.
SELECT * FROM sales LIMIT 2 OFFSET 1;
Result: rows 2 and 3 Why: OFFSET 1 skips the first row, LIMIT 2 then returns the next two.
Q23.
SELECT id FROM sales WHERE amount BETWEEN 100 AND 200;
Result: 1, 2, 4
Why: BETWEEN is inclusive (100 and 200 qualify); the NULL is excluded.
Joins and Windows
Q24.
SELECT region, SUM(amount) OVER (PARTITION BY region) AS region_total
FROM sales WHERE id = 1;
Result: East 300
Why: A window SUM over the East partition is 300, attached to row 1 without collapsing rows.
Q25.
SELECT id, ROW_NUMBER() OVER (ORDER BY amount DESC) AS rn
FROM sales WHERE amount IS NOT NULL;
Result: id 2 rn 1, id 4 rn 2, id 1 rn 3, id 5 rn 4 Why: ROW_NUMBER assigns ranks by descending amount: 200, 150, 100, 50.
Q26.
SELECT region, RANK() OVER (ORDER BY SUM(amount) DESC) AS r
FROM sales GROUP BY region;
Result: East rank 1, West rank 2, NULL rank 3 Why: Group sums are 300, 150, 50; RANK orders them descending.
Q27.
SELECT COUNT(*) FROM sales s1 JOIN sales s2 ON s1.region = s2.region;
Result: depends on NULL exclusion, here counts only matching non-NULL region pairs Why: Self-join on region matches East-East (2x2=4) and West-West (2x2=4); NULL regions do not match, giving 8.
Q28.
SELECT region, LAG(amount) OVER (PARTITION BY region ORDER BY id) AS prev
FROM sales WHERE region = 'East';
Result: id 1 prev NULL, id 2 prev 100 Why: LAG returns the previous row's amount within the partition; the first row has no predecessor so prev is NULL.
Quick Trap Table
| Trap | Rule to remember |
|---|---|
| COUNT(*) vs COUNT(col) | all rows vs non-NULL |
| arithmetic with NULL | yields NULL |
| = NULL | never true, use IS NULL |
| AVG | divides by non-NULL count |
| GROUP BY NULL | all NULLs one group |
| HAVING vs WHERE | after vs before aggregation |
| NULL ordering | engine-dependent |
| BETWEEN | inclusive bounds |
Frequently Asked Questions
Are query-output questions common in SQL interviews in 2026?
Yes. Candidates report that predicting the result of a GROUP BY, the count behaviour with NULLs, and the order of WHERE versus HAVING are the most repeated SQL output questions in analyst screens.
What is the most common SQL output trap?
NULL handling: COUNT(column) skips NULLs while COUNT(*) counts every row, and any arithmetic or comparison with NULL yields NULL. This single behaviour catches the most candidates.
How do I get fast at predicting SQL output?
Trace the logical order of clauses (FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY), watch NULL semantics in counts and comparisons, and know how aggregates ignore NULLs.
Why does AVG ignore NULLs in the denominator?
Because aggregate functions skip NULL inputs entirely, so AVG divides the sum of non-NULL values by the count of non-NULL values, not by the total row count.
Why is the order of NULLs in ORDER BY unpredictable?
Because the SQL standard leaves NULL sort position to the implementation, so engines differ. Specify NULLS FIRST or NULLS LAST explicitly when the position matters.
Related Articles
- SQL Interview Questions 2026, the master 50-question set
- SQL Joins Interview Questions 2026, join logic in depth
- SQL Indexing Interview Questions 2026, performance tuning
- SQL vs NoSQL Interview Questions 2026, database choices
Where output is engine-dependent, this guide says so honestly. Confirm any engine-specific behaviour on the official documentation. This guide reflects candidate-reported patterns and public preparation resources as of June 2026.
Methodology applied to this articlelast verified 8 Jun 2026
- No fabricated salary numbers or success rates. If we quote a range, it's sourced.
- No noun-substituted templates. This article was not generated by swapping company names in a stock prompt.
- No paid placements, sponsored coaching links, or affiliate-shilled course pushes.
Explore this topic cluster
More resources in Interview Questions
Use the category hub to browse similar questions, exam patterns, salary guides, and preparation resources related to this topic.
Paid contributor programme
Sat this this year? Share your story, earn ₹500.
First-person experience reports help future candidates prep smarter. We pay verified contributors ₹500 via UPI per accepted story - with byline.
Submit your story →Ready to practice?
Take a free timed mock test
Put what you learned into practice. Our mock tests match the 2026 pattern with timer, navigator, reveal, and score breakdown. No signup.
Start Free Mock Test →Related Articles
Airbnb Interview Questions 2026: Top Tech, HR & Behavioural Q&As for Freshers
Clearing Airbnb's fresher loop in 2026 comes down to preparing for the exact mix of questions across technical, behavioural,...
Airtel Interview Questions 2026: Top Tech, HR & Behavioural Q&As for Freshers
Clearing Airtel's fresher loop in 2026 comes down to preparing for the exact mix of questions across technical, behavioural,...
AMD Interview Questions 2026: Top Tech, HR & Behavioural Q&As for Freshers
Clearing AMD's fresher loop in 2026 comes down to preparing for the exact mix of questions across technical, behavioural,...
Atlassian Interview Questions 2026: Top Tech, HR & Behavioural Q&As for Freshers
Clearing Atlassian's fresher loop in 2026 comes down to preparing for the exact mix of questions across technical,...
Barclays Interview Questions 2026
_Last verified by [Aditya Sharma](/author/aditya-sharma/) · cross-checked against PapersAdda Hiring Pulse and...
More from PapersAdda
Accenture Interview Process 2026: Rounds & Prep
Accenture Interview Questions 2026 (with Answers for Freshers)
Adobe Interview Process 2026: Rounds, OA & Aptitude
Amazon Interview Process 2026: Full Loop + Bar Raiser