Loading, please wait...

Order By Clause

How To Use Order By Clause In SQL

 

Introduction:
In this article, you will learn what order by clause is and how to use order by clause in SQL.

The order by clause is used to arrange the data, either in ascending order or descending order, which belongs to the database tables. You can use more than one column in the order by clause.

 

Syntax

The basic syntax of order by clause is as follows:

select * from table_name order by [column1, column2, .. columnN];

 

Example

Step 1: We write the query of order by clause.

 

 

 

Now, select and execute this query.

 

Step 2: The output of this query is:

 

 

 

Now, we sort the result in descending order by employee ID.

 

Syntax

The basic syntax of order by clause is to arrange the data in descending order is as follows:

select * from table_name order by [column1, column2......] [asc | desc];

 

Step 3: Write the query for this statement.

 

 

 

Step 4: The output will be:

 

 

 

Summary:
Thus, we learned, how order by clause is used to arrange the data in a series in SQL.