Practice mode DBMS and SQL

Table Result(name, marks) has rows (‘Ali’,80), (‘Bina’,90), (‘Chand’,80), (‘Dua’,70). SELECT name FROM Result ORDER BY marks DESC, name ASC LIMIT 2; What is returned?

Correct answer A. Bina, Ali

Explanation

Rows are sorted by marks from highest to lowest, and the second key, name ascending, breaks ties. Bina (90) comes first. Ali and Chand both have 80, and alphabetically Ali comes before Chand, so Ali is second. LIMIT 2 keeps those two rows. Without the tie-breaker the order of Ali and Chand would not be guaranteed.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.