IAE Academy

GATE 2026 DA Q.60: solution and answer

GATE 2026 · DAQ.60 · 2 marks · NAT

Let Account be a relation as shown.

| AccNo | Balance |
|---|---|
| A1 | 5000 |
| A2 | 5000 |
| A3 | 10000 |
| A4 | 15000 |
| A5 | 18000 |

Consider the given SQL query.

SELECT AccNo FROM Account AS A
WHERE (SELECT COUNT(*) FROM Account AS B
WHERE A.Balance < B.Balance) >= (SELECT COUNT(*)
FROM Account AS C WHERE A.Balance > C.Balance)

The number of rows returned by the SQL query is ______ . (Answer in integer)

GATE 2026 DA question 60: A table titled Account with columns AccNo and Balance and five rows: A1 5000, A2 5000, A3 10000, A4 15000, A5 18000.Tap to open full size
Figure from the GATE 2026 DA paper. It is part of the question.
Figure description

A table titled Account with columns AccNo and Balance and five rows: A1 5000, A2 5000, A3 10000, A4 15000, A5 18000.

Answer and solution

ANSWER

The query returns 3 rows (A1, A2 and A3).

Official answer: 3Source: Official answer key, GATE 2026 DA (IIT Guwahati)

  1. The query is correlated. For each row of A, the first subquery counts the rows B with B.Balance strictly greater than A.Balance. The second subquery counts the rows C with C.Balance strictly less than A.Balance. The row is returned when the first count is at least the second.

  2. The balances are . Write for the count strictly greater and for the count strictly less than the outer row's balance.

  3. A1 (): (10000, 15000, 18000) and . Since , A1 is returned.

  4. A2 (): the balance equals A1's, so and . A2 is returned. The tie does not matter, because both comparisons are strict and the other row counts on neither side.

  5. A3 (): (15000, 18000) and (5000, 5000). Since , A3 is returned.

  6. A4 (): (18000) and (5000, 5000, 10000). Since is false, A4 is not returned.

  7. A5 (): and . Since is false, A5 is not returned.

  8. The rows returned are A1, A2 and A3, so the query returns rows.

KEY IDEA

For each outer row, a correlated subquery counts the rows with a strictly larger balance and the rows with a strictly smaller balance. The row qualifies when the larger-count is at least the smaller-count. Rows with equal balance fall in neither count.

WATCH OUT FOR

Counting tied balances (the two 5000 rows) as greater or smaller. Both comparisons are strict, so a tied row counts on neither side. Another slip is reversing the two counts, which would keep A3, A4 and A5 and still give 3 rows by coincidence of a different set. Evaluate each row explicitly.

From the GATE 2026 DA paper. Every question of this paper · Download the full paper · All 4 SQL questions, with notes

More SQL questions