ORDER BY Clause are used to short retrieved data. The default shorting is ascending order. If you want to short data in descending order you have to write ORDER BY DESC.
1.
SQL> select last_name, salary, department_id, commission_pct
2 from employees
3 where last_name like 'K%'
4 order by salary;
LAST_NAME SALARY DEPARTMENT_ID COMMISSION_PCT
------------------------- ---------- ------------- --------------
Khoo 3100 30
Kumar 6100 80 .1
Kaufling 7900 50
King 10000 80 .35
Kochhar C 17000 90
King 24000 90
6 rows selected.
2.
SQL> select last_name, salary, department_id, commission_pct
2 from employees
3 where last_name like 'K%'
4 order by salary desc;
LAST_NAME SALARY DEPARTMENT_ID COMMISSION_PCT
------------------------- ---------- ------------- --------------
King 24000 90
Kochhar C 17000 90
King 10000 80 .35
Kaufling 7900 50
Kumar 6100 80 .1
Khoo 3100 30
6 rows selected.
3.
SQL> select last_name, salary, department_id, commission_pct
2 from employees
3 where last_name like 'K%'
4 order by 2;
LAST_NAME SALARY DEPARTMENT_ID COMMISSION_PCT
------------------------- ---------- ------------- --------------
Khoo 3100 30
Kumar 6100 80 .1
Kaufling 7900 50
King 10000 80 .35
Kochhar C 17000 90
King 24000 90
6 rows selected.
4.
SQL> select last_name, salary, department_id, commission_pct
2 from employees
3 where last_name like 'K%'
4 order by 2 desc;
LAST_NAME SALARY DEPARTMENT_ID COMMISSION_PCT
------------------------- ---------- ------------- --------------
King 24000 90
Kochhar C 17000 90
King 10000 80 .35
Kaufling 7900 50
Kumar 6100 80 .1
Khoo 3100 30
6 rows selected.
SQL>
1 and 3 number query working similar. 2 and 4 number query also working similar.
1.
SQL> select last_name, salary, department_id, commission_pct
2 from employees
3 where last_name like 'K%'
4 order by salary;
LAST_NAME SALARY DEPARTMENT_ID COMMISSION_PCT
------------------------- ---------- ------------- --------------
Khoo 3100 30
Kumar 6100 80 .1
Kaufling 7900 50
King 10000 80 .35
Kochhar C 17000 90
King 24000 90
6 rows selected.
2.
SQL> select last_name, salary, department_id, commission_pct
2 from employees
3 where last_name like 'K%'
4 order by salary desc;
LAST_NAME SALARY DEPARTMENT_ID COMMISSION_PCT
------------------------- ---------- ------------- --------------
King 24000 90
Kochhar C 17000 90
King 10000 80 .35
Kaufling 7900 50
Kumar 6100 80 .1
Khoo 3100 30
6 rows selected.
3.
SQL> select last_name, salary, department_id, commission_pct
2 from employees
3 where last_name like 'K%'
4 order by 2;
LAST_NAME SALARY DEPARTMENT_ID COMMISSION_PCT
------------------------- ---------- ------------- --------------
Khoo 3100 30
Kumar 6100 80 .1
Kaufling 7900 50
King 10000 80 .35
Kochhar C 17000 90
King 24000 90
6 rows selected.
4.
SQL> select last_name, salary, department_id, commission_pct
2 from employees
3 where last_name like 'K%'
4 order by 2 desc;
LAST_NAME SALARY DEPARTMENT_ID COMMISSION_PCT
------------------------- ---------- ------------- --------------
King 24000 90
Kochhar C 17000 90
King 10000 80 .35
Kaufling 7900 50
Kumar 6100 80 .1
Khoo 3100 30
6 rows selected.
SQL>
1 and 3 number query working similar. 2 and 4 number query also working similar.
No comments:
Post a Comment