Download presentation
Presentation is loading. Please wait.
Published byWillis Dennis Modified over 8 years ago
1
1 Session 3 Welcome: To session 3-the fifth learning sequence “ Relational algebra “ Recap : In the previous learning sequences, we discussed the eight operators of relational algebra. Present learning: We shall explore the following topic: - Another operators.
2
2 Relational Algebra
3
3
4
4
5
uTwo basic operators wDivision wNatural-Join Operation uThe operators take two or more relations as inputs and give a new relation as a result.
6
Division Operation uSuited to queries that include the phrase “for all”. uLet r and s be relations on schemas R and S respectively where wR = (A 1, …, A m, B 1, …, B n ) wS = (B 1, …, B n ) The result of r s is a relation on schema R – S = (A 1, …, A m ) r s = { t | t R-S (r) u s ( tu r ) } r s
7
Division Operation – Example Relations r, s: r s:r s: A B 1212 AB 1231113461212311134612 r s
8
Another Division Example AB aaaaaaaaaaaaaaaa CD aabababbaabababb E 1111311111113111 Relations r, s: r s:r s: D abab E 1111 AB aaaa C r s
9
n Notation: r s Natural-Join Operation uLet r and s be relations on schemas R and S respectively. Then, r s is a relation on schema R S obtained as follows: wConsider each pair of tuples t r from r and t s from s. wIf t r and t s have the same value on each of the attributes in R S, add a tuple t to the result, where t has the same value as t r on r t has the same value as t s on s
10
n Notation: r s Natural-Join Operation uExample: R = (A, B, C, D) S = (E, B, D) wResult schema = (A, B, C, D, E) wr s is defined as: r.A, r.B, r.C, r.D, s.E ( r.B = s.B r.D = s.D (r x s))
11
Natural Join Operation – Example uRelations r, s: AB 1241212412 CD aababaabab B 1312313123 D aaabbaaabb E r AB 1111211112 CD aaaabaaaab E s r s
12
Outer Join uAn extension of the join operation that avoids loss of information. uComputes the join and then adds tuples form one relation that does not match tuples in the other relation to the result of the join. uUses null values: wnull signifies that the value is unknown or does not exist wAll comparisons involving null are (roughly speaking) false by definition. Will study precise meaning of comparisons with nulls later
13
Outer Join – Example uRelation loan n Relation borrower customer-nameloan-number Jones Smith Hayes L-170 L-230 L-155 3000 4000 1700 loan-numberamount L-170 L-230 L-260 branch-name Downtown Redwood Perryridge
14
Outer Join – Example uInner Join loan Borrower loan-numberamount L-170 L-230 3000 4000 customer-name Jones Smith branch-name Downtown Redwood Jones Smith null loan-numberamount L-170 L-230 L-260 3000 4000 1700 customer-namebranch-name Downtown Redwood Perryridge n Left Outer Join loan Borrower
15
Outer Join – Example uRight Outer Join loan borrower Loan borrower n Full Outer Join loan-numberamount L-170 L-230 L-155 3000 4000 null customer-name Jones Smith Hayes branch-name Downtown Redwood null loan-numberamount L-170 L-230 L-260 L-155 3000 4000 1700 null customer-name Jones Smith null Hayes branch-name Downtown Redwood Perryridge null
16
Example Queries (1) uFind all customers who have an account from at least the “Downtown” and the Uptown” branches. where CN denotes customer-name and BN denotes branch-name. Query 1 CN ( BN=“Downtown ” (depositor account)) CN ( BN=“Uptown ” (depositor account))
17
Example Queries (2) uFind all customers who have an account from at least the “Downtown” and the Uptown” branches. Query 2 customer-name, branch-name (depositor account) temp(branch-name ) ({(“Downtown”), (“Uptown”)})
18
uFind all customers who have an account at all branches located in Brooklyn city. Example Queries (3) customer-name, branch-name (depositor account) branch-name ( branch-city = “Brooklyn” (branch))
19
19 Relational Algebra Summary: In this learning sequence, we discussed another basic operators of the topic relational algebra.
20
20 END
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.