0
0
MySQLquery~5 mins

ORDER BY multiple columns in MySQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the ORDER BY clause do in SQL?
It sorts the rows returned by a query based on one or more columns, either in ascending (default) or descending order.
Click to reveal answer
beginner
How do you sort query results by multiple columns in SQL?
List the columns separated by commas in the ORDER BY clause, like ORDER BY column1, column2. The sorting happens first by column1, then by column2 within the same values of column1.
Click to reveal answer
beginner
What is the default sorting order when using ORDER BY without specifying ASC or DESC?
The default sorting order is ascending (ASC), which means from smallest to largest or alphabetically A to Z.
Click to reveal answer
intermediate
Write a query to sort employees first by department ascending, then by salary descending.
Example query: <br>SELECT * FROM employees ORDER BY department ASC, salary DESC;
Click to reveal answer
beginner
Why would you use multiple columns in an ORDER BY clause?
To organize data more precisely. For example, sorting by last name and then by first name helps list people alphabetically by full name.
Click to reveal answer
What happens if you write ORDER BY age, name in a query?
ARows are sorted by name first, then by age within the same name.
BRows are sorted by age first, then by name within the same age.
CRows are sorted randomly.
DQuery will return an error.
Which keyword sorts data in descending order?
ADOWN
BASC
CDESC
DREVERSE
If you want to sort by two columns, which is the correct syntax?
AORDER BY column1 AND column2
BORDER BY column1; ORDER BY column2
CORDER BY (column1, column2)
DORDER BY column1, column2
What is the default sort order if none is specified?
AAscending
BNo sorting
CRandom
DDescending
Which of these queries sorts employees by salary descending and then by name ascending?
AORDER BY salary DESC, name ASC
BORDER BY name ASC, salary DESC
CORDER BY salary, name
DORDER BY salary ASC, name DESC
Explain how to use the ORDER BY clause to sort data by multiple columns.
Think about sorting a list by last name, then first name.
You got /4 concepts.
    Describe a real-life example where sorting by multiple columns is useful.
    Imagine organizing a phone book or a store inventory.
    You got /3 concepts.