Tuesday, 19 July 2016

Where and Order by Clauses

Clauses:
We have two clauses used in this
1) Where
2) Order by

1) WHERE:- Its used to filter query.

Syntax: select * from <table_name> where <condition>;

Eg: Select *from Emp Where empno =101;

In above query we are using where clause to get where empno is having 101.

2) Order by : Its used to sort records.

Syntax: Select * from <table_name> order by <col> desc;

By default oracle will use ascending order. 
If you want output in descending order you have to use desc keyword after the
 column.

Ex: SQL> select * from student order by no;


 NO NAME MARKS
 --- ------- ---------
 1 Sree 100
 1 Ramana 300
 2 Ram 200
 2 Chinna 400
 3 Sreeram 
 4 Nithin
 5 Ravi
 6 Mahi

SQL> select * from student order by no desc;

NO NAME MARKS
 --- ------- ---------
 6 Mahi
 5 Ravi
 4 Nithin
 3 Sreeram
 2 Ram 200
 2 Chinna 400
 1 Sree 100
 1 Ramana 300

No comments:

Post a Comment