Friday 29 April 2016

SELECTION OPERATOR


It is possible to select only the required rows using WHERE clause of SELECT command. It implements selection operator of relational algebra. WHERE clause specifies the condition that rows must satisfy in order to be selected. The following example select rows where FEE is more than or equal to 5000.
select name, fee from courses
where fee >= 5000

NAME                     FEE

-------------------- ---------

VB.NET                 5500
ASP.NET                 5000


The following relational and logical operators are used to form condition of WHERE clause. Logical operators – AND, OR – are used to combine conditions. NOT operator reverses the result of the condition. If condition returns true, NOT will make the overall condition false.


Operator              Meaning 

 =                            Equal to
!= or <>                  Not equal to
>=                          Greater than or equal to
<=                          Less than or equal to
 >                           Greater than
<                            Less than
AND                     Logical ANDing
OR                        Logical Oring
NOT                     Negates result of condition.


The following SELECT command displays the courses where duration is more than 15 days and course fee is less than 4000.
select * from courses
where duration > 15 and fee < 4000;


CCODE    NAME       DURATION FEE      PREREQUISITE
 ----- -------------------- --------- --------- -----------------

c                  C programming      20 3500                 Computer Awareness


The following SELECT command retrieves the details of course with code ORA.
select * from courses where ccode = 'ora';



CCODE   NAME       DURATION FEE      PREREQUISITE
                                                                                                   

ora         Oracle database     25 4500               Windows


Note: When comparing strings, the case of the string must match. Lowercase letters are not equivalent to uppercase letters.

No comments:

Post a Comment