MySQL Questions and Answers – The order by Clauses – 2

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

Answer: a
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

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

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

Note: Join free Sanfoundry classes at Telegram or Youtube
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

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

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

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

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

Answer: b
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

Answer: a
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

Answer: b
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

Answer: b
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

Answer: b
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.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.