0% found this document useful (0 votes)
28 views

Database Systems: University of Gujrat

The document discusses logical operators such as AND, OR, and NOT that are used to combine conditions in SQL statements. It also covers precedence rules for operators and how parentheses can be used to override precedence. The document provides examples of SQL queries using logical operators to select employee records based on certain conditions. The document provides information on logical operators like AND, OR, and NOT that are used to join conditions in SQL statements. It also discusses precedence rules for operators and how parentheses can override precedence. Examples are given of SQL queries using logical operators to filter employee records that meet specific criteria. Logical operators AND, OR and NOT are examined which are used to combine conditions in
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Database Systems: University of Gujrat

The document discusses logical operators such as AND, OR, and NOT that are used to combine conditions in SQL statements. It also covers precedence rules for operators and how parentheses can be used to override precedence. The document provides examples of SQL queries using logical operators to select employee records based on certain conditions. The document provides information on logical operators like AND, OR, and NOT that are used to join conditions in SQL statements. It also discusses precedence rules for operators and how parentheses can override precedence. Examples are given of SQL queries using logical operators to filter employee records that meet specific criteria. Logical operators AND, OR and NOT are examined which are used to combine conditions in
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Database Systems

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

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 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.

You might also like