If your column values in mysql table contains more rows, then you can't get the highest and lowest values. On that time, you can sort the column values ascending and descending by 'ORDER BY' mysql command with 'ASC' and 'DESC'. The mysql query for sort column values in mysql table as follwos as:
SELECT * FROM table_name ORDER BY field_name ASC( for ascending)
SELECT * FROM table_name ORDER BY field_name DESC( for descending)
You can see the mysql table 'table1' which is sorted by id in ascending order and date in descending order.
Related Post:
SELECT * FROM table_name ORDER BY field_name ASC( for ascending)
SELECT * FROM table_name ORDER BY field_name DESC( for descending)
Order by in Mysql:
Consider the following table. table1 is name of this table.
Now we are going to sort column 'id' in ascending order. The mysql query for this:
SELECT * FROM table1 ORDER BY id ASC
Now you'll get output like this:
You can see the column 'id' values are sorting in ascending order.
SELECT * FROM table1 ORDER BY id ASC
Now you'll get output like this:
You can see the column 'id' values are sorting in ascending order.
Order by multiple columns in mysql:
You can sort the multiple columns in single mysql query. The mysql query as follows as:
SELECT * FROM table1 ORDER BY id ASC, date DESC
Where,
- The column 'id' got the first preference to sort
- Then the column 'date' is sort
Your output like this:
- The column 'id' got the first preference to sort
- Then the column 'date' is sort
Your output like this:
You can see the mysql table 'table1' which is sorted by id in ascending order and date in descending order.
Related Post: