0
0
SQLquery~5 mins

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

Choose your learning style9 modes available
Recall & Review
beginner
What does the SQL clause ORDER BY do?
The ORDER BY clause 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?
You list the columns separated by commas in the ORDER BY clause. For example: ORDER BY column1 ASC, column2 DESC sorts first by column1 ascending, then by column2 descending if there are ties.
Click to reveal answer
intermediate
Why would you use multiple columns in an ORDER BY clause?
Using multiple columns helps organize data more precisely. For example, sorting a list of people by last name and then by first name ensures all last names are grouped and within each group, first names are sorted.
Click to reveal answer
beginner
What is the default sort order in SQL when using ORDER BY?
The default sort order is ascending (smallest to largest or A to Z) if you do not specify ASC or DESC.
Click to reveal answer
beginner
Write a simple SQL query to select all columns from a table named Employees and sort by Department ascending and Salary descending.
SELECT * FROM Employees ORDER BY Department ASC, Salary DESC;
Click to reveal answer
What happens if you use ORDER BY column1, column2 in a SQL query?
ARows are sorted first by column1, then by column2 if there are ties in column1.
BRows are sorted only by column2.
CRows are sorted randomly.
DRows are sorted only by column1.
What is the default sorting order when you use ORDER BY column without specifying ASC or DESC?
ADescending order
BRandom order
CNo sorting
DAscending order
Which SQL clause is used to sort query results by multiple columns?
AWHERE
BGROUP BY
CORDER BY
DHAVING
How do you sort by Age descending and then by Name ascending?
AORDER BY Age DESC, Name ASC
BORDER BY Name DESC, Age ASC
CORDER BY Age ASC, Name DESC
DORDER BY Name ASC, Age DESC
If two rows have the same value in the first column of an ORDER BY clause, how are they sorted?
AThey remain in the original order
BThey are sorted by the next column in the ORDER BY list
CThey are sorted randomly
DThey are removed from the result
Explain how the ORDER BY clause works when sorting by multiple columns in SQL.
Think about sorting a list of names by last name then first name.
You got /4 concepts.
    Write an SQL query to select all data from a table called Products and sort by Category ascending and Price descending.
    Remember to separate columns with commas in ORDER BY.
    You got /2 concepts.