Indicate of ascend : Sort Order « Select Clause « SQL / MySQL

SQL / MySQL
1. Backup Load
2. Command MySQL
3. Cursor
4. Data Type
5. Database
6. Date Time
7. Flow Control
8. Function
9. Insert Delete Update
10. Join
11. Key
12. Math
13. Procedure Function
14. Select Clause
15. String
16. Table Index
17. Transaction
18. Trigger
19. User Permission
20. View
21. Where Clause
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
SQL / MySQL » Select Clause » Sort Order 
Indicate of ascend

/*
mysql> select * from Student;
+-----------+------------+-----------+
| StudentID | first_name | last_name |
+-----------+------------+-----------+
|         1 | John       | Jones     |
|         2 | Gary       | Burton    |
|         3 | Emily      | Scarlett  |
|         4 | Bruce      | Lee       |
|         5 | Anna       | Wolff     |
|         6 | Vic        | Andrews   |
|         7 | Steve      | Alaska    |
+-----------+------------+-----------+
7 rows in set (0.02 sec)

mysql> select * from Student ORDER BY StudentID DESC;
+-----------+------------+-----------+
| StudentID | first_name | last_name |
+-----------+------------+-----------+
|         7 | Steve      | Alaska    |
|         6 | Vic        | Andrews   |
|         5 | Anna       | Wolff     |
|         4 | Bruce      | Lee       |
|         3 | Emily      | Scarlett  |
|         2 | Gary       | Burton    |
|         1 | John       | Jones     |
+-----------+------------+-----------+
7 rows in set (0.01 sec)


*/  
Drop table Student;

CREATE TABLE Student (
   StudentID INT NOT NULL PRIMARY KEY,
   first_name      VARCHAR(50NOT NULL,
   last_name      VARCHAR(50NOT NULL
   
)TYPE = InnoDB;


INSERT INTO Student (StudentID,first_name, last_nameVALUES (4,'Bruce', 'Lee');

INSERT INTO Student (StudentID,first_name, last_nameVALUES (1,'John', 'Jones');
INSERT INTO Student (StudentID,first_name, last_nameVALUES (2,'Gary', 'Burton');
INSERT INTO Student (StudentID,first_name, last_nameVALUES (7,'Steve', 'Alaska');
INSERT INTO Student (StudentID,first_name, last_nameVALUES (5,'Anna', 'Wolff');
INSERT INTO Student (StudentID,first_name, last_nameVALUES (6,'Vic', 'Andrews');
INSERT INTO Student (StudentID,first_name, last_nameVALUES (3,'Emily', 'Scarlett');

select from Student;

select from Student ORDER BY StudentID DESC;

           
       
Related examples in the same category
1. Order result wiht ORDER
2. Use ORDER BY to list
3. Use two ORDER BY fields
4. Sorting Rows
5. Default sort order is ascending
6. To sort in reverse (descending) order
7. Sort on multiple columns
8. Sort columns in different directions
9. Order decending
10. Another decendingly
11. Order BY and Limit
12. Order row in select clause
13. Order two columns with different orders
14. Narrow down data with condition and order it
15. Simple ORDER by
16. Sorting Data
17. Use order by to sort the result
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.