Switch to full style
Include SQL commands
Post a reply

SQL ORDER BY

Mon Jul 16, 2012 1:31 pm

You can sort the selected results using ORDER BY command, for instance :

Code:

SELECT 
FROM 'Department' ORDER BY name


The results in the previous query will be in a ascending order (from A to Z), you can reverse the order direction by adding desc to the query.

Code:

SELECT 
FROM 'Department' ORDER BY name desc


You can use it for numeric values :
Code:

SELECT 
FROM 'Department' ORDER BY DepId desc


You can sort records with more than one column to handle the case with records have similar values in one column:
Code:

SELECT 
FROM 'Department' ORDER BY name,DepId desc




Post a reply
  Related Posts  to : SQL ORDER BY
 Difference in order between HashSet and ArrayList     -  
 How to display WooCommerce customer order details     -  
 Return an array with elements in reverse order     -  
 Input three numbers and then sort non descending order     -  
 rank order filter effects on image     -  
 How to change the default order on forums from ascending to     -  
 SELECT-Group by and Order by,Having Clause,count(),Joins     -