Question discussion

Consider the following SQL query. Which of the following options gives the same result (the second highest result)?

358821Medium DSSSB TGT Computer Science 0 replies 0 views
0
Consider the following SQL query. Which of the following options gives the same result (the second highest result)?
SELECT MAX(result) FROM student
WHERE result < (SELECT MAX(result) FROM student);
  • ASELECT result FROM student WHERE ROWNUM = 2 ORDER BY result DESC;
  • BSELECT TOP 2 result FROM student ORDER BY result DESC;
  • CSELECT result FROM student ORDER BY result DESC LIMIT 1 OFFSET 1;
  • DSELECT MAX(result) FROM student WHERE result < (SELECT MAX(result) FROM student);
Correct answer: D

Explanation

The inner query finds the highest result, and the outer query then selects the largest result that is less than it, which is the second highest result. Option 4 is this same nested query. ROWNUM = 2 with ORDER BY, TOP 2 (returns two rows) and LIMIT 1 OFFSET 1 (changes with duplicate values) do not return the second highest value in the same way.

Discussion 0

Nobody has replied yet. Start the discussion!