2. Logical Operators
Operator Meaning
AND Returns TRUE if both component
conditions are TRUE
OR Returns TRUE if either component
conditions are TRUE
NOT Returns TRUE if following condition is
FALSE
3. Using the AND operators
An employee who has a job title of CLERK and earn
more than $1100 will be selected.
4. Using the OR operators
An employee who has a job title of CLERK or earn more
than $1100 will be selected.
5. Using the NOT operators
Name and Job title of all the employees whose Job title is
not CLERK , MANAGER or ANALYST
6. Rules of Precedence
Order Evaluated Operator
1 All comparison
Operators
2 NOT
3 AND
4 OR
Override rules of precedence by using parentheses
7. Rules of Precedence
2
1
SELECT statement
reads as follows:
Select the row that
if an employee is a
PRESIDENT and
earn more than
$1500.
Or if the employee
is a SALESMAN.
8. Use of Parenthesis:
To force Priority
2
1 SELECT statement
reads as follows:
Select the row that
if an employee is a
PRESIDENT or
SALESMAN and if
the employee earn
more than $1500.
9. ORDER BY Clause
• Sort rows with the ORDER BY clause
–ASC: ascending order , default
–DESC: descending order
• The ORDER BY clause comes last in the
SELECT statement.
– SELECT expr
FROM table
[WHERE condition(s)]
[ORDER BY {column exp} [ASC|DESC]];
14. Assignments
1. Display the Name and Salary for all employees
whose salary is not in the range of $1500 and $
2850.
2. Select the Name. job and start date of employees
hired between February 20,1981 and May
1,1981.Order the query I ascending order by start
date.
3. Display the employee Name and department
number of all employees in departments 10 and
30 in alphabetic order by name.
15. 4. Display the name and job title of all employees
who do not have a manger.
5. Display the name , salary and commission for all
employees who earn commission. Sort data in
descending order of Salary and commission.
6. Display the name of all employees where the
third letter of their name is an A.
7. Display the name, salary and commission for all
employees whose job is clerk or analyst and their
salary is not equal to $ 1000.$3000 or $5000.