Column Names
SELECT
company, contact, phone FROM customers ORDER BY company
SELECT
company, contact, phone FROM customers ORDER BY company, contact
SELECT
company, contact, phone FROM customers ORDER BY state
Column Alias
SELECT
company CO, contact CT, phone PH FROM customers ORDER BY CO
SELECT
company, contact, phone FROM customers ORDER BY CO, CT
Select List Item Ordinal
Numbers
SELECT
company, contact, state FROM customers ORDER BY 3
SELECT
company, contact, state FROM customers ORDER BY 3, 1
Aggregates, Functions, Expressions
SELECT
customer_no, sum(amount) FROM orders GROUP BY customer_no
ORDER BY 2
SELECT
customer_no, count(distinct order_no) FROM orders GROUP BY
customer_no
ORDER
BY 2, 1
ASC, DESC
DESC
(Descending) sorts will NOT be optimized, meaning they may
increase the overall elapsed query time. ASC (Ascending) sorts
may be optimized, depending on the index installation.
SELECT
company, contact, phone FROM customers ORDER BY company asc
SELECT
customer_no, count(distinct order_no) FROM orders GROUP BY
customer_no
ORDER
BY 2 DESC, 1 ASC
top
|