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 multiple rows using 'order by' Clause


Topic

How to select the multiple rows and columns in an ordered manner?
How to sort multiple rows and columns?



Explanation

    We can also sort multiple columns in different directions as given in the below query.

mysql> select name, marks, address from student order by name,
marks desc;
+---------+-------+------------------+
| name    | marks | address          |
+---------+-------+------------------+
| anne    |   100 | downing street   |
| anne    |    80 | edinburgh        |
| david   |    98 | welling street   |
| jack    |    82 | victoria street  |
| michael |    75 | edinburgh        |
| mille   |    98 | victoria street  |
| steve   |   100 | 5th cross street |
| steve   |    75 | downing street   |
+---------+-------+------------------+
8 rows in set (0.00 sec)
    Here we have selected three columns name, marks and address. In this query we have sorted the column name alone in ascending order and we have additionally mentioned marks in descending order.

    So if there are same names, the highest mark will be taken as the first priority. In the above example query, there are 2 anne, so the anne with highest mark will be displayed first.




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