By admin | January 25, 2008

Arranging output in SQL

Remember ORDER BY is the last clause in the SELECT statement, which arranges the order after the SQL data are fetched

The ORDER BY clause arranges the  output of a SELECT statement in a particular order. It can be ascending or descending.

SELECT EMPNO,ENAME,SAL FROM EMP ORDER BY SAL;
 

The above SQL will display the result in the ascending order of SAL.

We can achieve the similar output by slightly reforming the statement, like

SELECT EMPNO,ENAME,SAL FROM EMP ORDER BY 3;

Notice SAL is the 3rd column to be displayed

SELECT EMPNO,ENAME,SAL FROM EMP ORDER BY SAL DESC;

will display the output in descending order.

You can use where condition in the sqame statement, but the ORDER BY clause should be the last one in the SELECT statement

Digg Facebook Technorati Bloglines

Email This Post Email This Post
Topics: Database |



Leave a Comment

Name:

E-Mail :

Website :

Comments :

Ad

Calendar

November 2008
M T W T F S S
« Oct «-»  
 12
3456789
10111213141516
17181920212223
24252627282930

Search

Polls

  • Who will rule the world?

    View Results

    Loading ... Loading ...