Content
ORDER BY sorts the result set in ascending or descending order. Control exactly how your data is presented.
Basic ORDER BY Syntax
SELECT * FROM table ORDER BY column;
Ascending Order (Default)
SELECT * FROM products ORDER BY price ASC;
Descending Order
SELECT * FROM products ORDER BY price DESC;
Multiple Column Sorting
SELECT * FROM employees
ORDER BY department ASC, salary DESC;
ORDER BY with LIMIT
SELECT * FROM products
ORDER BY sales DESC
LIMIT 10;
ORDER BY Column Position
SELECT name, price, category FROM products ORDER BY 2 DESC;
Generate Sorted Queries
AI2sql handles sorting automatically when you describe your needs.


