Ordering helps you see data in a clear, sorted way. It makes finding information easier by arranging results in a specific order.
0
0
Why ordering organizes results in MySQL
Introduction
When you want to list customers alphabetically by name.
When you need to see the newest orders first.
When you want to rank products by price from low to high.
When you want to organize students by their test scores.
When you want to group events by date in chronological order.
Syntax
MySQL
SELECT column1, column2 FROM table_name ORDER BY column1 [ASC|DESC];
ORDER BY sorts the results by one or more columns.
ASC means ascending order (smallest to largest or A to Z). It is the default.
DESC means descending order (largest to smallest or Z to A).
Examples
This lists customer names alphabetically from A to Z.
MySQL
SELECT name FROM customers ORDER BY name ASC;
This shows orders starting with the newest date first.
MySQL
SELECT order_id, order_date FROM orders ORDER BY order_date DESC;
This lists products by price from lowest to highest (default ascending).
MySQL
SELECT product_name, price FROM products ORDER BY price;
Sample Program
This creates a table of employees, adds three rows, and then lists employees ordered by salary from highest to lowest.
MySQL
CREATE TABLE employees (id INT, name VARCHAR(20), salary INT); INSERT INTO employees VALUES (1, 'Alice', 5000), (2, 'Bob', 3000), (3, 'Charlie', 4000); SELECT name, salary FROM employees ORDER BY salary DESC;
OutputSuccess
Important Notes
If you do not use ORDER BY, the database may return rows in any order.
You can order by multiple columns by separating them with commas.
Ordering can slow down queries on large tables if indexes are missing.
Summary
ORDER BY sorts query results to make data easier to understand.
Use ASC for ascending and DESC for descending order.
Ordering is useful for reports, lists, and ranking data.