MySQL SQLLesson 8Free preview
MySQL ORDER BY
This lesson is part of MySQL · All levels
Summary
The ORDER BY clause is used to sort the SELECT results based on one or more columns. By default the sequence is ascending, and you can add DESC to the down sequence. MySQL also accepts column position numbers like ORDER BY 2, but writing the column name explicitly is easier to read and safer.
Key points
- ORDER BY sort the result set, not change the order of the data in the table
- ASC sort of goes up and becomes a built-in option when it's not written.
- DESC produces a decreasing order, for example the most expensive price in the top order
- You can sort more than one column, with the order of the first column as the priority.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.