GateAI
SQL

GATE CSE 2011 · Q32

MCQ2 marksMedium

Time

Consider a database table T containing two columns X and Y each of type integer. After the creation of the table, one record (X=1, Y=1) is inserted in the table. Let MX and MY denote the respective maximum values of X and Y among all records in the table at any point in time. Using MX and MY, new records are inserted in the table 128 times with X and Y values being MX+1, 2*MY+1 respectively. It may be noted that each time after the insertion, values of MX and MY change. What will be the output of the following SQL query after the steps mentioned above are carried out? SELECT Y FROM T WHERE X=7;

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: A) 127

SQL

Initially, the table contains one row:

  • Initial state: (X1,Y1)=(1,1)(X_1, Y_1) = (1, 1), so MX=1MX = 1 and MY=1MY = 1.

In each subsequent insertion step kk (for k=1,2,…,128k = 1, 2, \dots, 128):

  • A new record is inserted with Xk+1=MX+1X_{k+1} = MX + 1 and Yk+1=2×MY+1Y_{k+1} = 2 \times MY + 1.

Tracing the values of XX and YY inserted into the table:

  • Step 1: X2=1+1=2X_2 = 1 + 1 = 2, Y2=2(1)+1=3=22−1Y_2 = 2(1) + 1 = 3 = 2^2 - 1

  • Step 2: X3=2+1=3X_3 = 2 + 1 = 3, Y3=2(3)+1=7=23−1Y_3 = 2(3) + 1 = 7 = 2^3 - 1

  • Step 3: X4=3+1=4X_4 = 3 + 1 = 4, Y4=2(7)+1=15=24−1Y_4 = 2(7) + 1 = 15 = 2^4 - 1

  • Step 4: X5=4+1=5X_5 = 4 + 1 = 5, Y5=2(15)+1=31=25−1Y_5 = 2(15) + 1 = 31 = 2^5 - 1

  • Step 5: X6=5+1=6X_6 = 5 + 1 = 6, Y6=2(31)+1=63=26−1Y_6 = 2(31) + 1 = 63 = 2^6 - 1

  • Step 6: X7=6+1=7X_7 = 6 + 1 = 7, Y7=2(63)+1=127=27−1Y_7 = 2(63) + 1 = 127 = 2^7 - 1

In general, for a given X=nX = n, the corresponding value of YY is 2n−12^n - 1.

For X=7X = 7:

Y=27−1=128−1=127Y = 2^7 - 1 = 128 - 1 = 127

Thus, the query SELECT Y FROM T WHERE X=7; returns 127 (Option A).

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This SQL previous year question is Q32 of the GATE CSE 2011 paper. Find more GATE CSE PYQs on SQL in Databases, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related SQL PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

SQL in GATE CSE

SQL has 17 GATE CSE PYQs across 14 papers from 2011 to 2025. 5 of them are 2-mark MCQs like this one, and it is the only one in GATE CSE 2011.

How GATE tests SQL

More from GATE CSE 2011

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2011 · Q32 · MCQ

Consider a database table T containing two columns X and Y each of type integer . After the creation of the table, one record (X=1, Y=1) is inserted in the table. Let MX and MY denote the respective maximum values of X and Y among all records in the table at any point in time. Using MX and MY, new records are inserted in the table 128 times with X and Y values being MX+1, 2*MY+1 respectively. It may be noted that each time after the insertion, values of MX and MY change. What will be the output of the following SQL query after the steps mentioned above are carried out? SELECT Y FROM T WHERE X=7;

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.