---
title: "How to sort the results of an SQL search query in ascending and descending order?"  
description: "How to sort the results of an SQL search query in ascending and descending order?"  
author: "Revati S Misra"  
published: 2023-10-09  
updated: 2023-10-10  
canonical: https://www.mindstick.com/forum/160082/how-to-sort-the-results-of-an-sql-search-query-in-ascending-and-descending-order  
category: "mssql server"  
tags: ["mssql server", "sql server", "sql"]  
reading_time: 2 minutes  

---

# How to sort the results of an SQL search query in ascending and descending order?

How to sort the [results](https://yourviews.mindstick.com/story/4497/usage-of-baking-soda-magical-results) of an [SQL](https://www.mindstick.com/articles/13115/types-of-keys-in-sql-or-oracle-database) [search query](https://www.mindstick.com/forum/160075/what-is-an-sql-search-query-and-how-is-it-different-from-a-regular-sql-query) in [ascending and descending](https://www.mindstick.com/forum/158905/how-do-you-use-the-order-by-clause-to-sort-query-results-in-ascending-and-descending-order) [order](https://www.mindstick.com/articles/12276/how-timely-order-deliveries-can-improve-customer-experience)?

## Replies

### Reply by Aryan Kumar

ou can sort the results of an SQL [search](https://www.mindstick.com/articles/65368/best-smo-services-company-in-hyderabad-improve-search-rankings) [query](https://www.mindstick.com/blog/202/sub-query-in-sqlserver) 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) using the **ORDER BY** clause. Here's how to do it:

**Ascending Order (default):** To sort the results in ascending order (from the smallest value to the largest or from A to Z), you don't need to specify the direction because it's the default. Here's an example:

```plaintext
SELECT column1, column2
FROM your_table
ORDER BY column1; -- This will sort column1 in ascending order
```

**Descending Order:** To sort the results in descending order (from the largest value to the smallest or from Z to A), you need to explicitly specify the direction using the **DESC** keyword. Here's an example:

```plaintext
SELECT column1, column2
FROM your_table
ORDER BY column1 DESC; -- This will sort column1 in descending order
```

You can also sort by multiple columns by listing them in the **ORDER BY** clause. Here's an example:

```plaintext
SELECT column1, column2
FROM your_table
ORDER BY column1 DESC, column2 ASC; -- Sort by column1 in descending order and then by column2 in ascending order
```

By using the **ORDER BY** clause with either **ASC** (ascending) or **DESC** (descending), you can control the sorting direction of your SQL query results to meet your specific needs.


---

Original Source: https://www.mindstick.com/forum/160082/how-to-sort-the-results-of-an-sql-search-query-in-ascending-and-descending-order

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
