Similar to the GROUP BY clause, the ORDER BY clause also determines how the data is displayed in the view and not so much what the view is displaying. The ORDER BY clause controls the order in which records appear in a view. The order can be determined by the numerical magnitude if it is a numerical data type, or the alphabetical order if it is a char data type.

There is also a functionality to ORDER BY that allows the user to determine if they want the records to show in ascending order or descending order. By default, if we say ORDER BY total_amount, this will order the view by the total amount spent in ascending order. If we would like to specify that we want the total amount spent to be ordered by descending order we would specify that in the statement, ORDER BY total_amount desc, tacking on desc at the end of the order by will accomplish this.

The ORDER BY clause is placed after the GROUP BY clause.

Click here for Part 5: JOINS