The ORDER BY clause in SQL is used to sort the result set in ascending or descending order based on one or more columns. The sort criteria does not have to be included in the SELECT statement, but the ORDER BY clause must be provided in the SELECT statement sent by the application if an ordering is required. Without this clause, the relational database system may return the rows in any order. The ORDER BY clause sorts the records in ascending order by default, but to sort the records in descending order, the DESC keyword is used. The ASC keyword is used to sort the data returned in ascending order. The ORDER BY clause can sort data by a single column or by multiple columns, and it can also sort the data in a preferred order. The ORDER BY clause is used with the SQL SELECT statement and is usually specified after the WHERE, HAVING, and GROUP BY clauses. The ORDER BY clause is not valid in views, inline functions, derived tables, and subqueries, unless either the TOP or OFFSET and FETCH clauses are also specified.