H I O X INDIA
MySQL Tutorial
 HOME  ||  Scripts  ||  Purchase  ||  Tutorials  ||  Images  ||  Tools  ||  Templates 
  :-)  Send Page   :-)   Feedback   :-)   Register   :-)   Links   :-)   Support   :-)
Español Français 中文 Deutsch
 Forums   Hosting   Internet Stats   Easy Calculation   FUN Games 

Mysql Tutorial
Introduction
How to Install
Database
Datatypes
Tables
INSERT
SELECT
UPDATE
DELETE
Operators
Functions
Ask Your Doubts
More about Mysql
Feedback




Sorting of Database Rows using 'order by' clause


Topic

How to select the database rows in an ordered manner?
What is the use of sorting of rows?
How to use Order By Clause?



Explanation

    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.






        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.


privacy policy     license     sitemap
© 2004-2009 HIOX INDIA - hioxindia.com

Other Links