This question is based on the following SQL table. Mr. Aman, a Computer…
2022
This question is based on the following SQL table.
Mr. Aman, a Computer Science teacher, maintains the details of his Class 12 students in an SQL table named MYSTUDENT.
ROLLNO | NAME | SEC | MARKS |
|---|---|---|---|
80105 | MARIA | A | 83.0 |
80108 | AMAR | B | 44.0 |
80109 | MANPREET | A | 92.0 |
80112 | SAMEER | A | 81.0 |
80115 | AKBAR | B | NULL |
Identify the most suitable SQL command to display the merit list of students such that:
Details are displayed in descending order of MARKS
If some students have the same MARKS, their details are displayed in ascending order of ROLLNO
- A.
SELECT * FROM MYSTUDENT ORDER BY DESC MARKS, ASC ROLLNO;
- B.
SELECT * FROM MYSTUDENT ORDER BY MARKS DESC, ROLLNO ASC;
- C.
SELECT * FROM MYSTUDENT ORDER BY MARKS; ROLLNO DESC, ASC;
- D.
SELECT * FROM MYSTUDENT ORDER BY MARKS DESC; ROLLNO ASC;
Attempted by 1568 students.
Show answer & explanation
Correct answer: B
Correct SQL command: SELECT * FROM MYSTUDENT ORDER BY MARKS DESC, ROLLNO ASC; Key idea: Sort first by MARKS in descending order so highest marks appear first; if MARKS are the same, sort those tied rows by ROLLNO in ascending order to break ties. Step 1: Use ORDER BY MARKS DESC to order by marks in descending order.
A video solution is available for this question — log in and enroll to watch it.