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
Email This Post
Topics:
Database |
