Specifies the sort order for the result set. The ORDER BY clause is not valid in subqueries.
There is no limit to the number of items in the ORDER BY clause.
If the ORDER BY clause is used with a UNION statement, then the columns on which you sort must be the column names or aliases specified in the first SELECT statement. For example, the first of the following SELECT statement succeeds, while the second fails:
Create t1 (col1 int, col2 int);
Create t2 (col3 int, col4 int);
SELECT * from t1 UNION SELECT * from t2 ORDER BY col1;
This statement succeeds because col1 belongs to the first table (t1)
SELECT * from t1 UNION SELECT * from t2 ORDER BY col3;
This statement fails because col3 does not belong to the first table (t1)