Ordering SQL query results using DESC Vs ASC

The purpose of Ascending or Descending order is to order the SQL results. Do not confuse with Order by clause. The Order by clause orders the results based on columns given in the SQL query. On top of ORDER BY the Ascending or Descending sort the rows.

The ordering rows in SQL you can say as sorting the rows.

SQL sort

Ascending and Descending in SQL

Short name for Ascending is ASC. The short name for Descending is DESC.

SQL Syntax for DESC and ASC

SELECT language,
       year
FROM proglang_tbl
ORDER BY year DESC, language ASC;

Explanation

The above result gives ordered results by YEAR. The ASC and DESC role is to sort the results.

DESC Vs ASC

  • By default all the results in ORDER BY are Ascending – default is ASC
  • In DESC, the order is highest to lowest value.
  • In Ascending, the order is , lowest to highest value.
  • The ASC and DESC works with ORDER BY clause.

Related

Advertisements

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.