- SQL Basics
- SQL Home
- SQL Syntax
- SQL RDBMS
- SQL Databases
- SQL Data Types
- SQL Operators
- SQL Expressions
- SQL Database
- SQL Create Database
- SQL Select Database
- SQL Drop Database
- SQL Table
- SQL Create Table
- SQL Drop Table
- SQL Keywords
- SQL Insert Into
- SQL Select
- SQL Where
- SQL And & Or
- SQL Update
- SQL Delete
- SQL Like
- SQL Select Top
- SQL Group By
- SQL Order By
- SQL Distinct
- SQL In
- SQL Between
- SQL Joins
- SQL Joins
- SQL Inner Join
- SQL Left Join
- SQL Right Join
- SQL Full Join
- SQL Constraints
- SQL Constraints
- SQL Unique
- SQL Not Null
- SQL Primary Key
- SQL Foreign Key
- SQL Check
- SQL Default
- SQL Create Index
- SQL Advance
- SQL Aliases
- SQL Union
- SQL Auto Increment
- SQL Views
- SQL Dates
- SQL Transactions
- SQL Injection
- SQL Test
- SQL Online Test
- Give Online Test
- All Test List
SQL Order By
SQL ORDER BY keyword is basically used to sort the result-set by one or more columns. Here is the general form of the ORDER BY keyword in SQL to sort the result-set by one/more columns:
SELECT column_name, column_name FROM table_name ORDER BY column_name ASC|DESC, column_name ASC|DESC;
Note - As the ORDER BY keyword in SQL sorts the records in ascending order. Therefore, if you want to sort the records in descending order, then use DESC keyword.
SQL ORDER BY Example
Here is an example of ORDER BY keyword in SQL. Let's consider the table named CUSTOMERS having the following records:

Following is an example, which would sort the result in ascending order by NAME and SALARY:
SELECT * FROM CUSTOMERS ORDER BY NAME, SALARY;
After querying the above SQL statements, you will get the following output:

Following is an example, which would sort the result in descending order by NAME:
SELECT * FROM CUSTOMERS ORDER BY NAME DESC;
After querying the above SQL statements, you will get the following output:

« Previous Tutorial Next Tutorial »
Like/Share Us on Facebook 😋