Week 4 - Lab Comparison Operators:: Operator Description Example
Week 4 - Lab Comparison Operators:: Operator Description Example
Week 4 - Lab Comparison Operators:: Operator Description Example
Comparison Operators:
Assume variable a holds 10 and variable b holds 20, then:
Operator
=
!=
<>
>
<
>=
<=
!<
!>
Description
Checks if the values of two
operands are equal or not, if yes
then condition becomes true.
Checks if the values of two
operands are equal or not, if values
are not equal then condition
becomes true.
Checks if the values of two
operands are equal or not, if values
are not equal then condition
becomes true.
Checks if the value of left operand
is greater than the value of right
operand, if yes then condition
becomes true.
Checks if the value of left operand
is less than the value of right
operand, if yes then condition
becomes true.
Checks if the value of left operand
is greater than or equal to the value
of right operand, if yes then
condition becomes true.
Example
(a = b) is not true.
(a <= b) is true.
(a != b) is true.
(a <> b) is true.
(a < b) is true.
(a !< b) is false.
(a !> b) is true.
Logical Operators:
Operator
AND
BETWEEN
EXISTS
IN
LIKE
Description
The AND operator allows the existence of multiple
conditions in an SQL statement's WHERE clause.
The BETWEEN operator is used to search for values
that are within a set of values, given the minimum value
and the maximum value.
The EXISTS operator is used to search for the
presence of a row in a specified table that meets
certain criteria.
The IN operator is used to compare a value to a list of
literal values that have been specified.
The LIKE operator is used to compare a value to
NOT
OR
IS NULL
Syntax:
Consider the basic syntax of the SELECT statement as follows:
SELECT column1, column2, columnN
FROM table_name
WHERE [CONDITION|EXPRESSION];
AND/OR Clause:
Syntax:
SELECT column1, column2....columnN
FROM table_name
WHERE CONDITION-1 {AND|OR} CONDITION-2;
IN Condition:
It tests whether a value is present in a list of values or subquery.
Syntax:
SELECT column1, column2....columnN
FROM table_name
WHERE column_name IN (val-1, val-2,...val-N);
An underscore (_) in the pattern matches exactly one character in the value.
A percent sign (%) in the pattern can match zero or more characters. The pattern '%' cannot match
a null.
Syntax:
SELECT column1, column2....columnN
FROM table_name
WHERE column_name LIKE { PATTERN };
varchar2(13),
dept
'ACCOUNTING', 'NEW YORK');
dept
'RESEARCH', 'DALLAS');
dept
'SALES', 'CHICAGO');
dept
'OPERATIONS', 'BOSTON');
2850, null, 30
);
insert into emp
values(
7782, 'CLARK', 'MANAGER', 7839,
to_date('9-6-1981','dd-mm-yyyy'),
2450, null, 10
);
insert into emp
values(
7566, 'JONES', 'MANAGER', 7839,
to_date('2-4-1981','dd-mm-yyyy'),
2975, null, 20
);
insert into emp
values(
7788, 'SCOTT', 'ANALYST', 7566,
to_date('13-JUL-87','dd-mm-rr') - 85,
3000, null, 20
);
insert into emp
values(
7902, 'FORD', 'ANALYST', 7566,
to_date('3-12-1981','dd-mm-yyyy'),
3000, null, 20
);
insert into emp
values(
7369, 'SMITH', 'CLERK', 7902,
to_date('17-12-1980','dd-mm-yyyy'),
800, null, 20
);
insert into emp
values(
7499, 'ALLEN', 'SALESMAN', 7698,
to_date('20-2-1981','dd-mm-yyyy'),
1600, 300, 30
);
insert into emp
values(
7521, 'WARD', 'SALESMAN', 7698,
to_date('22-2-1981','dd-mm-yyyy'),
1250, 500, 30
);
insert into emp
values(
7654, 'MARTIN', 'SALESMAN', 7698,
to_date('28-9-1981','dd-mm-yyyy'),
1250, 1400, 30
);
insert into emp
values(
7844, 'TURNER', 'SALESMAN', 7698,
to_date('8-9-1981','dd-mm-yyyy'),
1500, 0, 30
);
insert into emp
values(
7876, 'ADAMS', 'CLERK', 7788,
to_date('13-JUL-87', 'dd-mm-rr') - 51,
1100, null, 20
);
insert into emp
values(
7900, 'JAMES', 'CLERK', 7698,
to_date('3-12-1981','dd-mm-yyyy'),
950, null, 30
);
insert into emp
values(
7934, 'MILLER', 'CLERK', 7782,
to_date('23-1-1982','dd-mm-yyyy'),
1300, null, 10
);
1. Display Firstname , Lastname together with Alias as Fullname from student table.
2. Display employee name , commission and salary+10*commission as Total from scott.emp
3. Select unique deptno with job from scott.emp.
4. Select all the columns from scott.emp where sal is greater than equal to 1500
5. select only employee name from scott.emp whose employee number is less than 7782;
6. Select employee name from scott.emp where employee number is not equal to 7782;
7. Select employee name from scott.emp whose hiredate is 17th dec 1980.
8.select ename,sal,comm from scott.emp where 1=2;
9. select ename,sal,comm from scott.emp where 2=2;
10. select employee name , salary , commission from scott.emp where employee number is
greater than 0
11. select ename,sal,comm from scott.emp where comm=comm;
12. Select employee name , salary and commission from scott.emp whose salary is less than
equal to commission
13. By using IN operator in the where condition , display employee name , salary and job from
scott.emp where jobs are in 'CLERK','SALESMAN','ANALYST'
14. By using between in where condition display employee name , salary from scott.emp where
salary is between 1000 and 1500
15. Display employeenumber , employee name from scott.emp where employee name starts with
letter M
16. Display employee name , salary , job from scott.emp where job is SALESMAN or
PRESIDENT and salary is greater than 1500