0
0
MySQLquery~5 mins

ORDER BY single column in MySQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the ORDER BY clause do in a SQL query?
It sorts the rows returned by the query based on one or more columns, either in ascending or descending order.
Click to reveal answer
beginner
How do you sort query results by a single column in ascending order?
Use ORDER BY column_name ASC. ASC means ascending order and is the default if not specified.
Click to reveal answer
beginner
How do you sort query results by a single column in descending order?
Use ORDER BY column_name DESC. DESC means descending order.
Click to reveal answer
beginner
What happens if you use ORDER BY without specifying ASC or DESC?
The results are sorted in ascending order by default.
Click to reveal answer
beginner
Write a simple SQL query to select all columns from a table named employees and order the results by the last_name column.
SELECT * FROM employees ORDER BY last_name;
Click to reveal answer
What does ORDER BY salary DESC do?
ASorts salaries from highest to lowest
BSorts salaries from lowest to highest
CFilters salaries greater than DESC
DGroups salaries by DESC
Which keyword sorts data in ascending order?
ASORT
BDESC
CASC
DORDER
What is the default sort order if you write ORDER BY age without ASC or DESC?
ADescending
BAscending
CNo sorting
DRandom
Which SQL clause is used to sort query results?
AHAVING
BGROUP BY
CWHERE
DORDER BY
How would you sort a table named products by the price column in ascending order?
ASELECT * FROM products ORDER BY price ASC;
BSELECT * FROM products SORT BY price;
CSELECT * FROM products ORDER BY price DESC;
DSELECT * FROM products GROUP BY price;
Explain how to use the ORDER BY clause to sort data by a single column in SQL.
Think about how you tell SQL to arrange rows by one column.
You got /4 concepts.
    Write an example SQL query that selects all data from a table and sorts it by a column named date_created in descending order.
    Use ORDER BY with DESC to sort newest first.
    You got /3 concepts.