Loading, please wait...

Sorting

How to use Sorting Results in SQL

 

Introduction:
In this article, you will learn, what does sorting result mean and how to use sorting results in SQL.

With the help of this query, we assign the data in ascending or descending order. Some SQL query generate results automatically in an ascending order. To change the data in the descending order, we use DESC keyword and in an ascending order, we use ASC keyword.

 

Syntax

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

 

 

Example

Step 1: We write the query to arrange the data, according to our condition.

 

 

 

Now, select and execute this query.

 

Step 2: The result of this query will be:

 

 

 

This query is also used to arrange the data in the descending order by student name. The syntax of order by clause, which would be used to sort the data is as follows:

 

Syntax

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

 

 

Step 3: We write the query.

 

 

 

Now, select and execute this query.

 

Step 4: The result of this query will be:

 

 

 

In the sorting result, this query is used to set the data according to our conditions.

 

Step 5: We write the query to retrieve the data.

 

 

 

Now, select and execute this query.

 

Step 6: The result of this query will be:

 

 

 

Summary:
Thus, we learned that sorting the results is used to sort the data in SQL tables.