Database Systems Lab
IT[243]
Lab #:04
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
An employee who has a job title of CLERK and earn
more than $1100 will be selected.
Using the OR operators
An employee who has a job title of CLERK or earn more
than $1100 will be selected.
Using the NOT 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
Override rules of precedence by using parentheses
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.
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.
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
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.
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.
Database systems administration traning  04

Database systems administration traning 04

  • 1.
  • 2.
    Logical Operators Operator Meaning ANDReturns 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 ANDoperators An employee who has a job title of CLERK and earn more than $1100 will be selected.
  • 4.
    Using the ORoperators An employee who has a job title of CLERK or earn more than $1100 will be selected.
  • 5.
    Using the NOToperators Name and Job title of all the employees whose Job title is not CLERK , MANAGER or ANALYST
  • 6.
    Rules of Precedence OrderEvaluated Operator 1 All comparison Operators 2 NOT 3 AND 4 OR Override rules of precedence by using parentheses
  • 7.
    Rules of Precedence 2 1 SELECTstatement 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: Toforce 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]];
  • 10.
  • 11.
    Sorting in DescendingOrder Sorting in Descending Order
  • 12.
    Sorting by ColumnAlias Column Alias Sorting by Column Alias
  • 13.
    Sorting by multipleColumns Sorting by multiple Columns
  • 14.
    Assignments 1. Display theName 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 thename 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.