MySQL Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
Mysql Tutorial
Introduction
How to Install
Database
Datatypes
Tables
INSERT
SELECT
UPDATE
DELETE
Operators
Functions
Ask Your Doubts
Feedback
 





Order By MySQL


Tutorials Mysql

Topic
How to sort Table using MySQL Order By Clause ?


Explanation

Order By MySQL :

    In the preceding examples, the query for selected rows are displayed in no particular order. We can also select the rows to display in an ordered format using ORDER BY Clause.

    The following example query will sort the rows in an ascending order based on the marks.
mysql> select name, marks from student order by marks;
+---------+-------+
| name    | marks |
+---------+-------+
| michael |    75 |
| steve   |    75 |
| anne    |    80 |
| jack    |    82 |
| david   |    98 |
| mille   |    98 |
| steve   |   100 |
| anne    |   100 |
+---------+-------+
8 rows in set (0.03 sec)
    We can also sort the orders in descending order. In the below example query the marks are sorted in descending order.

mysql> select name, marks from student order by marks desc;
+---------+-------+
| name    | marks |
+---------+-------+
| steve   |   100 |
| anne    |   100 |
| david   |    98 |
| mille   |    98 |
| jack    |    82 |
| anne    |    80 |
| michael |    75 |
| steve   |    75 |
+---------+-------+
8 rows in set (0.00 sec)
    Next we can see how to sort the multiple columns.
    These examples helps you to use the order by mysql query.





A Note

MySQL is the most popular open source Relational database Management system (RDBMS). Being a open source anyone can use and change the software for their needs. Hope you enjoy this tutorial. We welcome your Valuable feedbacks or suggestions on this MySQL tutorial. This is a copyright content.


Other Links

web hosting