SQL TutorialLesson 6Free preview
SQL Order By
This lesson is part of SQL · All levels
Summary
ORDER BY is used to sort the query results based on one or more columns. Intuitively the sequence is ascending or ascending; write DESC to sort down. The order can also be based on columns that are not shown in SELECT.
Key points
- The built-in sequence is ASC or ascending; use DESC to descend.
- Order by is written after WHERE, GROUP BY, or HAVING.
- You can sort out many columns at once with different priorities.
- You can sort by the order of the column numbers on SELECT, for example ORDER BY 2.
- The text sequence follows the character collation on the database setting.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.