How to sort rows with an ORDER BY clause

The syntax of the ORDER BY clause

      ORDER BY expression [ASC|DESC] [, expression [ASC|DESC]] ...
      

Sort by one column in ascending sequence

      SELECT productName, listPrice, discountPercent 
      FROM products 
      WHERE listPrice < 500 
      ORDER BY productName;
      
2nd 2 rows image

Sort by one column in descending sequence

      SELECT productName, listPrice, discountPercent 
      FROM products 
      WHERE listPrice < 500 
      ORDER BY listPrice DESC;
      
2nd 2 rows image

Sort by two columns

      SELECT productName, listPrice, discountPercent 
      FROM products 
      WHERE categoryID = 1 
      ORDER BY discountPercent, listPrice DESC;
      
2nd 2 rows image

Description

Back