---
title: "How do you use the ORDER BY clause to sort query results in ascending and descending order?"  
description: "How do you use the ORDER BY clause to sort query results in ascending and descending order?"  
author: "Revati S Misra"  
published: 2023-06-30  
updated: 2023-07-02  
canonical: https://www.mindstick.com/forum/158905/how-do-you-use-the-order-by-clause-to-sort-query-results-in-ascending-and-descending-order  
category: "mssql server"  
tags: ["sql server", "sql"]  
reading_time: 2 minutes  

---

# How do you use the ORDER BY clause to sort query results in ascending and descending order?

How do you use the ORDER BY [clause](https://www.mindstick.com/forum/33937/difference-between-throw-exception-and-throw-clause) to sort [query](https://www.mindstick.com/blog/202/sub-query-in-sqlserver) [results](https://yourviews.mindstick.com/story/4497/usage-of-baking-soda-magical-results) in ascending and [descending order](https://answers.mindstick.com/qa/36839/how-do-i-sort-a-series-of-number-ascending-or-descending-order-in-assembly-language-8086)?

## Replies

### Reply by Aryan Kumar

The [ORDER](https://www.mindstick.com/articles/12276/how-timely-order-deliveries-can-improve-customer-experience) BY clause in SQL is used to sort the results of a SELECT statement. By default, the ORDER BY clause sorts the results in ascending order. To sort the results in descending order, you can use the DESC keyword.

For example, the following SELECT statement will return all of the rows from the `customers` table, sorted by the `customer_name` column in ascending order:

SQL

```plaintext
SELECT * FROM customers ORDER BY customer_name;
```

To sort the results in descending order, you can use the following SELECT statement:

SQL

```plaintext
SELECT * FROM customers ORDER BY customer_name DESC;
```

You can also sort the results by multiple columns. To do this, you simply specify the names of the columns, separated by commas, in the ORDER BY clause. For example, the following SELECT statement will return all of the rows from the `customers` table, sorted by the `customer_name` column in ascending order, and then by the `customer_id` column in ascending order:

SQL

```plaintext
SELECT * FROM customers ORDER BY customer_name, customer_id;
```

You can also specify the direction of sorting for each column. To do this, you can use the ASC keyword for ascending order or the DESC keyword for descending order. For example, the following SELECT statement will return all of the rows from the `customers` table, sorted by the `customer_name` column in descending order, and then by the `customer_id` column in ascending order:

SQL

```plaintext
SELECT * FROM customers ORDER BY customer_name DESC, customer_id;
```


---

Original Source: https://www.mindstick.com/forum/158905/how-do-you-use-the-order-by-clause-to-sort-query-results-in-ascending-and-descending-order

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
