Consider a database table T containing two columns and each of type . After the creation of the table, one record is inserted in the table.
Let and denote the respective maximum values of and among all records in the table at any point in time. Using and , new records are inserted in the table times with and values being respectively. It may be noted that each time after the insertion, values of and 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;
View worked solution
Answer: A
Let us trace the values of and inserted into the table step-by-step.
Initial State (Step 0):
Only one record exists in the table:
Here, the maximum values are and .
Step 1:
New record inserted: .
Now, and .
Step 2:
New record inserted: .
Now, and .
Step 3:
New record inserted: .
Now, and .
By observing the pattern for the -th insertion step:
We are looking for the record where :
For , the corresponding value of is:
Thus, the query SELECT Y FROM T WHERE X=7; will return 127.
Free practice · Your answers on this page are not saved.
