MySQL Sort & Group Data Guide
In MySQL, you can use the ORDER BY clause to sort data and the GROUP BY clause to group data.
- Sort the data.
SELECT * FROM table_name ORDER BY column_name ASC/DESC;
ASC stands for ascending order, while DESC stands for descending order.
- Grouping the data.
SELECT column_name, COUNT(*) FROM table_name GROUP BY column_name;
This will group by the specified column and calculate the number of rows in each group. Multiple columns can be grouped using the GROUP BY clause, such as:
SELECT column1, column2, COUNT(*) FROM table_name GROUP BY column1, column2;