| SELECT column_name(s)
FROM table_name
ORDER BY column_name(s) ASC or DESC; |
Notes:- Choose ASC for Ascending order or DESC for Descending order.
The SQL ORDER BY keyword simply orders results by specified column(s) in either ascending or descending order.
In this SQL sample we will use the database table ‘tblCompany’.
| Company_ID |
CompanyName |
Address |
Town |
Sales |
| 1 |
SQL Sample |
1 Sample St |
Hamburg |
10000 |
| 2 |
SQL Code Land |
2 Code Rd |
Hamburg |
20000 |
| 3 |
Sample Code World |
66 SQL St |
Curry |
18000 |
| 4 |
SQL Reference Ltd |
34 Reference St |
Pisa |
17000 |
In this example we will order the table tblCompany using the Sales column in descending order.
Use the SELECT statement below:
| SELECT * FROM tblCompany ORDER BY Sales DESC; |
The table of results will look like this:
| Company_ID |
CompanyName |
Address |
Town |
Sales |
| 1 |
SQL Sample |
1 Sample St |
Hamburg |
10000 |
| 4 |
SQL Reference Ltd |
34 Reference St |
Pisa |
17000 |
| 3 |
Sample Code World |
66 SQL St |
Curry |
18000 |
| 2 |
SQL Code Land |
2 Code Rd |
Hamburg |
20000 |
In this SQL sample we will use the database table ‘tblCompany’.
| Company_ID |
CompanyName |
Address |
Town |
Sales |
| 1 |
SQL Sample |
1 Sample St |
Hamburg |
10000 |
| 2 |
SQL Code Land |
2 Code Rd |
Hamburg |
20000 |
| 3 |
Sample Code World |
66 SQL St |
Curry |
18000 |
| 4 |
SQL Reference Ltd |
34 Reference St |
Pisa |
17000 |
In this example we will order the table tblCompany using the Sales column in ascending order.
Use the SELECT statement below:
| SELECT * FROM tblCompany ORDER BY Sales ASC; |
The table of results will look like this:
| Company_ID |
CompanyName |
Address |
Town |
Sales |
| 2 |
SQL Code Land |
2 Code Rd |
Hamburg |
20000 |
| 3 |
Sample Code World |
66 SQL St |
Curry |
18000 |
| 4 |
SQL Reference Ltd |
34 Reference St |
Pisa |
17000 |
| 1 |
SQL Sample |
1 Sample St |
Hamburg |
10000 |
Related SQL Sample Code: