Contents
SQL ORDER BY Keyword: Main Tips
- The keyword ORDER BY is used for sorting the result-set that is created using the SELECT statement.
- Using this statement you can sort the result-set by one or multiple columns in an ascending or descending order.
- ORDER BY sorts in an ascending order by default.
Syntax of SQL ORDER BY Keyword
Pros Main Features
- Easy to use with a learn-by-doing approach
- Offers quality content
- Gamified in-browser coding experience
- The price matches the quality
- Suitable for learners ranging from beginner to advanced
- Free certificates of completion
- Focused on data science skills
- Flexible learning timetable
Pros Main Features
- Simplistic design (no unnecessary information)
- High-quality courses (even the free ones)
- Variety of features
- Nanodegree programs
- Suitable for enterprises
- Paid Certificates of completion
Pros Main Features
- A wide range of learning programs
- University-level courses
- Easy to navigate
- Verified certificates
- Free learning track available
- University-level courses
- Suitable for enterprises
- Verified certificates of completion
Demo Database
In this example, we are using a basic SQL database.
Right here we have a section from the table called "Users":
ID | Username | Password | |
---|---|---|---|
1 | alfredfutter | [email protected] | secret1 |
2 | atrujillo | [email protected] | secret2 |
3 | moreno.antonio | [email protected] | secret3 |
4 | hardythomas | [email protected] | secret4 |
5 | bergluns | [email protected] | secret5 |
The following SQL statement selects all users from the "users" table, sorted by the "email" column:
SQL ORDER BY Keyword ORDER BY DESC
This statement will select every user from the table called "users", and sort them in a descending order by the "email" column:
SQL ORDER BY Keyword ORDER BY Several Columns
This statement will select every user from the table called "users", and sort them in an ascending order by the "email" and the "username" columns:
This statement will select every user from the table called "users", and sort them in a descending order by the "email" and the "username" columns: