

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MySQL order by from highest to lowest value?
To order by from highest to lowest value, you can use ORDER BY DESC command −
select *from yourTableName order by yourColumnName DESC;
If you want the result from lowest to highest, you can use ORDER BY ASC command −
select *from yourTableName order by yourColumnName ASC;
Let us first create a table −
mysql> create table DemoTable ( Value int ); Query OK, 0 rows affected (0.56 sec)
Insert records in the table using insert command −
mysql> insert into DemoTable values(134); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(245); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(451); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(1090); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(789); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(434); Query OK, 1 row affected (0.22 sec)
Display records from the table using select command −
mysql> select *from DemoTable;
This will produce the following output −
+-------+ | Value | +-------+ | 134 | | 245 | | 451 | | 1090 | | 789 | | 434 | +-------+ 6 rows in set (0.00 sec)
Case 1 −Order by from highest to lowest value −
mysql> select *from DemoTable order by Value DESC;
This will produce the following output −
+-------+ | Value | +-------+ | 1090 | | 789 | | 451 | | 434 | | 245 | | 134 | +-------+ 6 rows in set (0.07 sec)
Case 2 −Order by from lowest to highest value −
mysql> select *from DemoTable order by Value ASC;
This will produce the following output −
+-------+ | Value | +-------+ | 134 | | 245 | | 434 | | 451 | | 789 | | 1090 | +-------+ 6 rows in set (0.00 sec)
- Related Questions & Answers
- How to order by the highest value from two columns in MySQL?
- Highest and lowest value difference of array JavaScript
- Java Program to get the lowest and highest value in TreeSet
- Program to find the final ranking of teams in order from highest to lowest rank in python
- How to sort by value with MySQL ORDER BY?
- MySQL ORDER BY with custom field value
- Highest and lowest in an array JavaScript
- A single MySQL query to find the highest and lowest among two tables?
- ORDER BY specific field value first in MySQL
- MySQL order from a different starting value?
- Select nth highest value in MySQL
- Program to find out the minimum cost path between the lowest value vertex to the highest value vertex (Python)
- Is there a default ORDER BY value in MySQL?
- Set a certain value first with MySQL ORDER BY?
- Order by desc except a single value in MySQL
Advertisements