250+ TOP MCQs on The order by Clauses and Answers

MySQL Multiple Choice Questions on “The order by Clauses”.

1. Keyword “ASC” and “DESC” cannot be used without which clause in Mysql?
a) ORDER BY
b) GROUP BY
c) SELECT
d) HAVING

Answer: a
Clarification: “ASC” or “DESC” are used to sort the result set in ascending or descending order therefore they cannot be used without “ORDER BY” clause.

2. What is the significance of “ORDER BY emp_id DESC” in the following MySQL command?

SELECT emp_id, fname, lname
FROM person
ORDER BY emp_id DESC;

a) Data of emp_id will be sorted in descending order
b) Data of emp_id will be sorted in ascending order
c) Data of emp_id will be sorted in either ascending or descending order
d) All of the mentioned

Answer: a
Clarification: Keyword “DESC” will sort the data in descending order.

3. What is the significance of “ORDER BY emp_id ASC” in the following MySQL command?

SELECT emp_id, fname, lname
FROM person
ORDER BY emp_id ASC;

a) Data of emp_id will be sorted in descending order
b) Data of emp_id will be sorted in ascending order
c) Data of emp_id will be sorted in either ascending or descending order
d) All of the mentioned

Answer: b
Clarification: Keyword “ASC” will sort the data in ascending order.

4. If emp_id contain the following set {9, 7, 6, 4, 3, 1, 2}, what will be the output on execution of the following MySQL command?

SELECT emp_id
FROM person
ORDER BY emp_id DESC;

a) {9, 7, 6, 4, 3, 1, 2}
b) {1, 2, 3, 4, 6, 7, 9}
c) {2, 1, 3, 4, 6, 7, 9}
d) None of the mentioned

  250+ TOP MCQs on How MySQL Handles Invalid Data Values and Answers

Answer: a
Clarification: “DESC” clause sort the emp_id in the descending order.

5. If emp_id contain the following set {9, 7, 6, 4, 3, 1, 2}, what will be the output on execution of the following MySQL command?

SELECT emp_id
FROM person
ORDER BY emp_id ASC;

a) {9, 7, 6, 4, 3, 1, 2}
b) {1, 2, 3, 4, 6, 7, 9}
c) {2, 1, 3, 4, 6, 7, 9}
d) None of the mentioned

Answer: b
Clarification: “ASC” clause sort the emp_id in the ascending order.

6. Find odd one out?
a) GROUP BY
b) DESC
c) ASC
d) ORDER BY

Answer: a
Clarification: “ORDER BY”, “DESC”, “ASC” are related to sorting whereas “GROUP BY” is not related to sorting.

7. Is there any error in the following MySQL command?

SELECT emp_id, title, start_date, fname, fed_id
FROM person
ORDER BY RIGHT (fed_id, 3);

a) Yes
b) No error
c) Depends
d) None of the mentioned

Answer: b
Clarification: “ORDER BY” clause can be used with expression such as fed_id, which is a social security no like 111, 111, 111, therefore, we sort it taking only three digits from right.

8. Is there any error in the following MySQL command?

SELECT emp_id, title, start_date, fname, fed_id
FROM person
ORDER BY LEFT (fed_id, 3);

a) Yes
b) No error
c) Depends
d) None of the mentioned

Answer: b
Clarification: “ORDER BY” clause can be used with an expression such as fed_id which is a social security no like 111, 111, 111, therefore, we sort it taking only three digits from left.

  250+ TOP MCQs on The Where Clauses and Answers

9. Is there any error in the following MySQL command?

SELECT emp_id, title, start_date, fname, fed_id
FROM person
ORDER BY 2, 5;

a) Yes
b) No
c) Depends
d) None of the mentioned

Answer: b
Clarification: “ORDER BY” clause can be used with Place holders. Here “2” represent column “title” and “5” represent “fed_id”. Therefore it looks like “ORDER BY title, fed_id”.

Leave a Comment

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

Scroll to Top