Junior — Middle
What is the main function of the ORDER BY clause in SQL queries?
sobes.tech AI
Answer from AI
The ORDER BY clause in SQL is used to sort the results of a query by one or more columns. It determines the order of the output rows — ascending (ASC) or descending (DESC).
Example:
SELECT * FROM Employees ORDER BY LastName ASC, FirstName DESC;
In this example, the results will be sorted first by last name in alphabetical order, and in case of a tie, by first name in reverse order.