This set of MySQL Multiple Choice Questions & Answers (MCQs) focuses on “The order by Clauses – 2”.
1. Keyword “ASC” and “DESC” cannot be used without which clause in Mysql?
a) ORDER BY
b) GROUP BY
c) SELECT
d) HAVING
View Answer
Explanation: “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
View Answer
Explanation: 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
View Answer
Explanation: 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
View Answer
Explanation: “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
View Answer
Explanation: “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
View Answer
Explanation: “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
View Answer
Explanation: “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
View Answer
Explanation: “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.
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
View Answer
Explanation: “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”.
Sanfoundry Global Education & Learning Series – MySQL Database.
To practice all areas of MySQL Database, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Apply for Programming Internship
- Check Information Technology Books
- Check MySQL Books
- Practice Programming MCQs