Database Systems: University of Gujrat
Database Systems: University of Gujrat
Lab #:04
M. Shafiq
FACULTY OF CS & IT
UNIVERSITY OF GUJRAT
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
Using the AND operators
Name and Job title of all the employees whose Job title
is not CLERK , MANAGER or ANALYST
Rules of Precedence
Order Evaluated Operator
1 All comparison
Operators
2 NOT
3 AND
4 OR
2 SELECT statement
reads as follows:
1
Select the row that
if an employee is a
PRESIDENT and
earn more than
$1500.
Or if the employee
is a SALESMAN.
Use of Parenthesis:
To force Priority
1 SELECT statement
reads as follows:
2
Select the row that
if an employee is a
PRESIDENT or
SALESMAN and if
the employee earn
more than $1500.
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]];
ORDER BY Clause
Default
Order
Sorting in Descending Order
Sorting in
Descending
Order
Sorting by Column Alias
Column
Alias
Sorting by
Column Alias
Sorting by multiple Columns
Sorting by
multiple
Columns
Home Work
Assignment:
Given to you in Printed form.
Lab 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.
1. Display the name and job title of all employees who
do not have a manger.
2. Display the name , salary and commission for all
employees who earn commission. Sort data in
descending order of Salary and commission.
3. Display the name of all employees where the third
letter of their name is an A.
4. 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.