mysql order by
时间: 2023-12-26 19:19:41 浏览: 143
mysql排序查询
ORDER BY is a clause in MySQL used to sort the result set of a query based on one or more columns. It allows you to specify the sorting order, such as ascending (ASC) or descending (DESC).
To use ORDER BY, you can provide the column name(s) you want to sort by after the clause. For example:
```sql
SELECT column1, column2
FROM table_name
ORDER BY column1 ASC;
```
This will sort the result set based on the values in `column1` in ascending order. If you want to sort in descending order, you can use `DESC` instead:
```sql
SELECT column1, column2
FROM table_name
ORDER BY column1 DESC;
```
You can also sort by multiple columns by providing them in the ORDER BY clause:
```sql
SELECT column1, column2
FROM table_name
ORDER BY column1 ASC, column2 DESC;
```
This will first sort the result set by `column1` in ascending order, and then within each group of equal values in `column1`, it will sort by `column2` in descending order.
阅读全文