To determine the order in which results are returned, use the ORDER BY clause. The ORDER BY clause must be the last clause, the SELECT statement.
SELECT ENAME, JOB
FROM EMP
ORDER BY ENAME;
By default, data is sorted in ascending order (Ascending) - from the smallest to the largest numbers from earlier to later dates, and strings are sorted by NLS settings (defined when creating the database).
To reverse the sort order to use the word DESC (DESCENDING) used directly after the column name specified in the ORDER BY clause.
SELECT ENAME, JOB, HireDate
FROM EMP
HireDate ORDER BY DESC;
You can sort by multiple columns, then the ORDER BY keyword to specify the columns, after which we want to sort.
SELECT ENAME, JOB, DEPTNO
FROM EMP
ORDER BY DEPTNO, ENAME;
The names of the columns, after which we sort, must be specified in the SELECT clause.
Sorting only query result on the screen. The data in the tables are not sorted.
No comments:
Post a Comment