Sorting Query Output by Multiple Columns in SQL Server


Can the Query Output Be Sorted by Multiple Columns in SQL Server?



You can specifying multiple columns in the ORDER BY clause as shown in the following example statement, which returns rows sorted by "tag" and "counts" values:

SELECT tag, counts, url, created 
   FROM fyi_links ORDER BY tag, counts
tab     counts  url                     created
DBA     390           2006-01-01
DBA     960          2005-01-01
DBA     972       2007-05-19
DEV     120       2006-04-30
DEV     439             2004-01-01
SQA     728       2007-05-19
SQA     828       2003-01-01


Sorting Query Output in Descending Order in SQL Server

Sorting Query Output with ORDER BY Clauses in SQL Server

Using SELECT Statements and GROUP BY Clauses in SQL Server

⇑⇑ SQL Server Database Tutorials

2016-10-26, 1468🔥, 0💬