PL/SQL Order By

The ORDER BY clause is used to order rows returned in an select statement.
With ORDER BY clause you can use parameters ASC or DESC to specify ascending order and descending order.

Order By example

 
SELECT * FROM course ORDER BY price, name;

SELECT * FROM course ORDER BY price ASC, name ASC;

SELECT * FROM course ORDER BY 5, 2;

Output is the same for all 3 select statements

COURSE_ID NAME DESCRIPTION DURATION PRICE
3 HTML5 Learn HTML 5 1 week 10
1 SQL 1 SQL course for beginners 1 week 10
5 CSS Learn CSS 2 week 20
2 SQL 2 SQL course for advanced 2 week 50
4 PHP PHP course 4 week 75

Order By example

 
SELECT o.order_id, s.student_id, s.first_name, s.last_name
FROM students s, 
(SELECT * FROM orders ORDER BY order_id DESC) o
WHERE s.student_id=o.student_id
AND ROWNUM=1;

Output

ORDER_ID STUDENT_ID FIRST_NAME LAST_NAME
22 4 Emily PETERSON