[go: up one dir, main page]

0% found this document useful (0 votes)
4 views3 pages

Nested Database Huzaifa

Nested operations in relational algebra involve using the result of one operation as input for another, akin to SQL subqueries. The document illustrates this concept with examples involving product categories and prices, demonstrating how to combine conditions using AND and OR. The final result showcases products that meet specified criteria from the Employees relation.

Uploaded by

ahmadd8572
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Nested Database Huzaifa

Nested operations in relational algebra involve using the result of one operation as input for another, akin to SQL subqueries. The document illustrates this concept with examples involving product categories and prices, demonstrating how to combine conditions using AND and OR. The final result showcases products that meet specified criteria from the Employees relation.

Uploaded by

ahmadd8572
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

ABDUL HUZAIFA

DATABASE SYSTEMS
2420040302-009
MA’AM MASHAL

DEPARTMENT OF COMPUTER SCIENCES AND


SOFTWARE ENGINEERING
WHAT IS NESTED OPERATION IN RELATIONAL ALGEBRA?

Nested Operations:

Nested operations in relational algebra refer to queries that use one operation as an input for
another operation. This is similar to subqueries in SQL. The result of one operation is used as
the operand for another operation.

Example: Finding with AND and OR

Consider a relation (table) named Employees:

Product ID Product Name Category Price Stock


301 Laptop Electronics 1000 15
302 Chair Furniture 150 50
303 Smart Phone Electronics 800 20
304 Desk Furniture 200 30
305 Refrigrator Appliances 1200 10

Problem: Using AND and OR with Nested Operations

1. Find products in the Electronics category with a Price > 900.


2. Find products in either the Furniture or Appliances categories.
3. Combine both conditions using a nested operation.

Solution in Relational Algebra


AND Condition Find products in the Electronics category with a Price > 900:
𝜎 𝐶 𝑎 𝑡 𝑒 𝑔 𝑜 𝑟 𝑦 = ′ 𝐸 𝑙 𝑒 𝑐 𝑡 𝑟 𝑜 𝑛 𝑖 𝑐 𝑠 ′ ∧ 𝑃 𝑟 𝑖 𝑐 𝑒 > 900 ( 𝑃 𝑟 𝑜 𝑑 𝑢 𝑐 𝑡 𝑠 ) σ Category= ′
Electronics ′ ∧Price>900 (Products)
Result:

Product ID Product Name Category Price Stock


301 Laptop Electronics 1000 15
OR Condition
nd products in either the Furniture or Appliances categories:
𝜎𝐶𝑎𝑡𝑒𝑔𝑜𝑟𝑦=′𝐹𝑢𝑟𝑛𝑖𝑡𝑢𝑟𝑒′∨𝐶𝑎𝑡𝑒𝑔𝑜𝑟𝑦=′𝐴𝑝𝑝𝑙𝑖𝑎𝑛𝑐𝑒𝑠′
(𝑃𝑟𝑜𝑑𝑢𝑐𝑡𝑠)
Result:

Product ID Product Name Category Price Stock


302 Chair Furniture 150 50
304 Desk Furniture 200 30
305 Refrigrator Appliances 1200 10

Nested Operation (Combine AND and OR)


Find employees who satisfy either of these conditions:
• Category = 'Electronics' AND Price > 900
• Category = 'Furniture' OR Category = 'Appliances'

σ Category= ′ Electronics ′ ∧Price>900 (Products)∪


σ Category= ′ Furniture ′ ∨Category= ′ Appliances ′ (Products)

Result:

Product ID Product Name Category Price Stock


301 Laptop Electronics 1000 15
302 Chair Furniture 150 50
304 Desk Furniture 200 30
305 Refrigrator
Appliances Appliences
1200 1200
10 10

You might also like