Difference between revisions of "ORDER BY Clause"

From rbachwiki
Jump to navigation Jump to search
(Created page with " *When sorting in ascending order, values are listed in this order: 1. Blank and special characters 2. Numeric values 3. Character values (uppercase first) 4. NULL values * Un...")
 
Line 9: Line 9:
  FROM publisher
  FROM publisher
  ORDER BY name DESC
  ORDER BY name DESC
You can also use the ORDER BY clause with the optional NULLS FIRST or NULLS
LAST keywords to change the order for listing NULL values. By default, NULL values are
listed last when results are sorted in ascending order and first when they’re sorted in descending
order.
SELECT lastname, firstname, state, referred
FROM customers
WHERE  state = 'CA'
ORDER BY referred NULLS FIRST;


[[#Rules for Dates|Back To Top]]-[[Main_Page| Home]] - [[Oracle_SQL|Category]]
[[#Rules for Dates|Back To Top]]-[[Main_Page| Home]] - [[Oracle_SQL|Category]]

Revision as of 20:11, 24 October 2017

  • When sorting in ascending order, values are listed in this order:

1. Blank and special characters 2. Numeric values 3. Character values (uppercase first) 4. NULL values

  • Unless you specify “DESC” for descending, the ORDER BY clause sorts in ascending order by default.
SELECT * 
FROM publisher
ORDER BY name DESC

You can also use the ORDER BY clause with the optional NULLS FIRST or NULLS LAST keywords to change the order for listing NULL values. By default, NULL values are listed last when results are sorted in ascending order and first when they’re sorted in descending order.

SELECT lastname, firstname, state, referred
FROM customers
WHERE  state = 'CA'
ORDER BY referred NULLS FIRST;

Back To Top- Home - Category