How To Sort Query Output in Descending Order in MS SQL Server?
Submitted by: AdministratorIf you want to sort a column in descending order, you can specify the DESC keyword in the ORDER BY clause. The following SELECT statement first sorts the "tag" in descending order, then sorts the "counts" in ascending order:
SELECT tag, counts, url, created
FROM ggl_links ORDER BY tag DESC, counts
GO
<pre>
tab counts url created
SQA 728 globalguideline.com/sql 2007-05-19
SQA 828 www.winrunner.com 2003-01-01
DEV 120 globalguideline.com/xml 2006-04-30
DEV 439 www.php.net 2004-01-01
DBA 390 www.mysql.com 2006-01-01
DBA 960 www.oracle.com 2005-01-01
DBA 972 globalguideline.com 2007-05-19
</pre>
Submitted by: Administrator
SELECT tag, counts, url, created
FROM ggl_links ORDER BY tag DESC, counts
GO
<pre>
tab counts url created
SQA 728 globalguideline.com/sql 2007-05-19
SQA 828 www.winrunner.com 2003-01-01
DEV 120 globalguideline.com/xml 2006-04-30
DEV 439 www.php.net 2004-01-01
DBA 390 www.mysql.com 2006-01-01
DBA 960 www.oracle.com 2005-01-01
DBA 972 globalguideline.com 2007-05-19
</pre>
Submitted by: Administrator
Read Online MS SQL Server Job Interview Questions And Answers
Top MS SQL Server Questions
☺ | How To Get the Definition of a View Out of the SQL Server? |
☺ | What Happens If Strings Are Casted into Wrong Code Pages in MS SQL Server? |
☺ | PHP MSSQL - How To Display a Past Time in Days, Hours and Minutes? |
☺ | How To Create a View on an Existing Table in MS SQL Server? |
☺ | How To Select All Columns of All Rows from a Table with a SELECT statement in MS SQL Server? |
Top Databases Programming Categories
☺ | RDBMS Interview Questions. |
☺ | SQL Interview Questions. |
☺ | SSRS Interview Questions. |
☺ | Database Administrator (DBA) Interview Questions. |
☺ | Sybase Interview Questions. |