Basic Sorting
Note
The rows fetched by a
SELECT
statement are ordered by default based on the date and time of insertion, with the oldest inserted row at the top and the most recently inserted row at the bottom. In the upcoming sections, we will learn how to insert rows into tables.
Summary:
- We can sort the results of a
SELECT
statement by using anORDER BY
clause; - The syntax of the
ORDER BY
clause is:ORDER BY column_name [ASC|DESC]
; - The keywords
ASC
orDESC
can be optionally used to specify the sorting order; - Usage Example:
SELECT * FROM students ORDER BY age DESC
.
1. Which clause can be used for ordering the retrieved data?
2. What is the correct syntax for using the ORDER BY clause?
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Ask me questions about this topic
Summarize this chapter
Show real-world examples
Awesome!
Completion rate improved to 1.72
Basic Sorting
Swipe to show menu
Note
The rows fetched by a
SELECT
statement are ordered by default based on the date and time of insertion, with the oldest inserted row at the top and the most recently inserted row at the bottom. In the upcoming sections, we will learn how to insert rows into tables.
Summary:
- We can sort the results of a
SELECT
statement by using anORDER BY
clause; - The syntax of the
ORDER BY
clause is:ORDER BY column_name [ASC|DESC]
; - The keywords
ASC
orDESC
can be optionally used to specify the sorting order; - Usage Example:
SELECT * FROM students ORDER BY age DESC
.
1. Which clause can be used for ordering the retrieved data?
2. What is the correct syntax for using the ORDER BY clause?
Thanks for your feedback!