Intro
Use the ORDER BY keyword to sort the resulting record set in either ascending or descending order
Sample Data
This is the table we will use as an example:
SELECT * FROM ar_invoices
| invoice# | customer# | salesperson# | invoice_date | invoice_amount | amount_paid | current_month_interest_charges | total_interest_charges |
|---|---|---|---|---|---|---|---|
| 1 | 1 | 1 | 2019-06-17 10:43:53.727 | 100.00 | 1.00 | 0.00 | 0.00 |
| 2 | 2 | 2 | 2019-05-28 10:43:53.727 | 50.00 | 0.00 | 5.00 | 10.00 |
| 3 | 3 | 2 | 2019-06-17 10:43:53.727 | 70.00 | 0.00 | 10.00 | 20.00 |
| 4 | 2 | 1 | 2019-07-07 10:43:53.727 | 80.00 | 0.00 | 0.00 | 0.00 |
Syntax
SELECT column1, column2, ...
FROM table_name
ORDER BY column1, column2, ... ASC|DESC
SELECT invoice#,
invoice_amount
FROM ar_invoices
ORDER BY invoice_amount DESC
| invoice# | invoice_amount |
|---|---|
| 1 | 100.00 |
| 4 | 80.00 |
| 3 | 70.00 |
| 2 | 50.00 |