pcplans.com § Help and Support How to: using SQL the ORDER BY clause  

How to: using SQL the ORDER BY clause

Article ID:0302
Last Review:Thursday, January 08, 2009
Revision:3.0

INTRODUCTION

How to: using SQL the ORDER BY clause

symptomsIMPORTANT

How to: using SQL the ORDER BY clause


IMPORTANT

How to: using SQL the ORDER BY clause
ORDER BY is an optional clause which will allow you to display the results of your query in a sorted order
back to the top

How to: using SQL the ORDER BY clause


ORDER BY clause ORDER BY is an optional clause which will allow you to display the results of your query in a sorted order (either ascending order or descending order) based on the columns that you specify to order by.


ORDER BY clause syntax:
SELECT column1, SUM(column2)
FROM "list-of-tables"
ORDER BY 
"column-list" [ASC | DESC];
[ ] = optional


This statement will select the employee_id, dept, name, age,
and salary from the employee_info table where the dept equals
'Sales' and will list the results in Ascending (default)
order based on their Salary.

ASC = Ascending Order - default
DESC = Descending Order
For example:


SELECT employee_id, dept, name, age, salary
FROM employee_info
WHERE dept = 'Sales'
ORDER BY salary;

If you would like to order based on multiple columns, you must
seperate the columns with commas. For example:


SELECT employee_id, dept, name, age, salary
FROM employee_info
WHERE dept = 'Sales'
ORDER BY salary, age DESC;





  • NOTE: How to: using SQL the ORDER BY clause
  • back to the top




    Last Reviewed:1/8/2009
    Keywords: kbHow kbhowtoHow kbHOWTOHow #0302 kbAudITProHow



        Contact

       ©1999-2008 Support at pcplans.com