Example - Sorting Results in Ascending Order To sort your results in ascending order, you can specify the ASC attribute. If no value (ASC or DESC) is provided after a field in the ORDER BY clause, the sort order will default to ascending order. Let's explore this further. ...
[ORDER BY 排序字段 [ASC | DESC] [,排序字段 [ASC | DESC] ...]];使用ORDER BY子句可以对查询结果进行排序,ORDER BY子句一定要写在所有查询语句的最后;详细介绍Restricting and Sorting Data Limit the rows that are retrieved by a query 限制从查询中返回的行...
3.排序 orderby子句可以很方便地对返回的数据进行排序。orderby子句对返回的序列中的元素,根据指定的排序类型,使用默认比较器进行排序。其中,ascending表示按顺序排列,为默认方式;descending表示按逆序排列。若要把筛选的数据进行逆序排列,需要在查询语句中加上descending修饰符。 代码如下: 1 var result = from Stu in...
order by birthdate; Sorting single columns select title,gross from films where title like'M%'order by title; Sorting single columns (DESC) To order results in descending order, you can put the keyword DESC after your ORDER BY. For example, to get all the names in the people table, in ...
SELECT[COLUMN NAME]FROM[TABLE NAME]ORDER BY[COLUMN 1] ASCindicates ascending order. (This value is default sorting for SQL syntax) DESCindicates descending order. EXAMPLE#1 : TableGameScores let's see some simple sorting from the SQL statement usingORDER BYSQL statement : ...
The ORDER BY clause can include multiple columns in different sorting order (ascending or descending). When you include multiple columns with the ORDER BY clause, it will sort the records based on the first column, and if any two or more records have the same value in the first ORDER BY ...
The default sorting is ascending and is specified with theASCkeyword, and you don't need to explicitly add it, but if you want to sort by descending order, you need to use theDESCkeyword. If we use the query above and just addDESCat the end as follows: ...
USEtempdb; GOCREATETABLE#t1 (nameNVARCHAR(15)COLLATELatin1_General_CI_AI); GOINSERTINTO#t1VALUES(N'Sánchez'), (N'Sanchez'), (N'sánchez'), (N'sanchez');-- This query uses the collation specified for the column 'name' for sorting.SELECTnameFROM#t1ORDERBYname;-- This query uses the...
Sort Type: Ascending or Descending sorting of results. Sort Order: Order to use in sorting results if multiple columns or expressions are to be used (for example, sorting first by department and then by salary within each department). Grouping: Specifies whether to insert a GROUP BY clause. ...
SELECT*FROMtable_nameORDERBY[column_name]ASC|DESC In SQL ORDER BY clause, we need to define ascending or descending order in which result needs to be sorted. ASC: We can specifyASCto sort the result in ascending order DESC: We can specifyDESCto sort the result in descending order ...