H I O X INDIA
MySQL Tutorial
Google
Web hscripts.com
 HOME  ||  Scripts  ||  Purchase  ||  Tutorials  ||  Images  ||  Tools  ||  Directories 
  :-)  Send Page   :-)   Feedback   :-)   Register   :-)   Links   :-)   Support   :-)   Bookmarks :-)  
 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
Feedback





Sorting rows using 'order by' clause


Topic

How to select the rows in an ordered manner?
What is the use of sorting 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.




others


        MySQL is the most popular open source database Management system. 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-2005 HIOX INDIA - hioxindia.com

Other Links