Friday, March 13, 2015

Using Comparison Condition to filter rows.

Oracle provides the following comparison operator to filter rows.

Operator
Operation
=
Equal
> 
Greater Than
< 
Less than
>=
Greater Than or Equal
<=
Less than or Equal
BETWEEN (Lowest Value)  AND (Highest Value)
Between Two Value
IN
List of value
LIKE
Match pattern
IS NULL
Value is null
IS NOT NULL
Value is not null.

----- This query shows data from employees table those employees department id is 90.

SQL> select last_name, salary, department_id
  2  from employees
  3  where department_id=90;

LAST_NAME                     SALARY DEPARTMENT_ID
------------------------- ---------- -------------
King                           24000            90
Kochhar C                      17000            90
De Haan                        17000            90

SQL>

----- 

SQL> select last_name, salary, department_id
  2  from employees
  3  where salary > 20000;

LAST_NAME                     SALARY DEPARTMENT_ID
------------------------- ---------- -------------
King                           24000            90

SQL>

----- 

SQL> select last_name, salary, department_id
  2  from employees
  3  where salary >=24000;

LAST_NAME                     SALARY DEPARTMENT_ID
------------------------- ---------- -------------
King                           24000            90

SQL>

-----

SQL> select last_name, salary, department_id
  2  from employees
  3  where salary between 17000 and 20000;

LAST_NAME                     SALARY DEPARTMENT_ID
------------------------- ---------- -------------
Kochhar C                      17000            90
De Haan                        17000            90

SQL>

-----

SQL> select last_name, salary, department_id, commission_pct
  2  from employees
  3  where department_id = 90
  4  and commission_pct is null;

LAST_NAME                     SALARY DEPARTMENT_ID COMMISSION_PCT
------------------------- ---------- ------------- --------------
King                           24000            90
Kochhar C                      17000            90
De Haan                        17000            90

SQL>

----- 

SQL> select last_name, salary, department_id, commission_pct
  2  from employees
  3  where department_id in (80,90);

LAST_NAME                     SALARY DEPARTMENT_ID COMMISSION_PCT
------------------------- ---------- ------------- --------------
King                           24000            90
Kochhar C                      17000            90
De Haan                        17000            90
Russell                        14000            80             .4
Partners                       13500            80             .3
Errazuriz                      12000            80             .3

------ This query show data from employees those last name start with K.


SQL> select last_name, salary, department_id, commission_pct
  2  from employees
  3  where last_name like 'K%';

LAST_NAME                     SALARY DEPARTMENT_ID COMMISSION_PCT
------------------------- ---------- ------------- --------------
Kaufling                        7900            50
Khoo                            3100            30
King                           10000            80            .35
King                           24000            90
Kochhar C                      17000            90
Kumar                           6100            80             .1

6 rows selected.


No comments:

Post a Comment