Junior — Middle
Can you explain what the ORDER BY operator does in SQL queries?
sobes.tech AI
Answer from AI
The ORDER BY operator in SQL is used to sort the query results by one or more columns. By default, sorting is in ascending order (ASC), but you can explicitly specify descending order (DESC).
Example:
SELECT * FROM employees ORDER BY last_name ASC, first_name 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.
Thus, ORDER BY allows you to control the order of data output from the database.