Presentation is loading. Please wait.

Presentation is loading. Please wait.

Relational Algebra Continued CMSC 461 Michael Wilson.

Similar presentations


Presentation on theme: "Relational Algebra Continued CMSC 461 Michael Wilson."— Presentation transcript:

1 Relational Algebra Continued CMSC 461 Michael Wilson

2 Additional operations  Intersection  Division  Natural join

3 Intersection  The intersection of two relations  Find the elements of both relations that are the same  Must have the same attributes!  Notation: R ∩ S

4 Intersection (Relation R) addresslastContacted contactPhoneNumber numberTypecontactName 111 Great Street 1 day ago 555 5555CellPhil 8 Get Out of Here Way Last week 555 7777WorkBob 7 RUN! Drive 2 years ago 555 8888CellOctavio

5 Intersection (Relation S) addresslastContacted contactPhoneNumber numberTypecontactName 111 Great Street 1 day ago 555 5555CellPhil 123 Not So Great Street Last month 555 6666LandlineHenry 7 RUN! Drive 2 years ago 555 8888CellOctavio

6 R ∩ S addresslastContacted contactPhoneNumber numberTypecontactName 111 Great Street 1 day ago 555 5555CellPhil 7 RUN! Drive 2 years ago 555 8888CellOctavio

7 Division  This one is a little complicated  Two relations, R and S  R consists of attributes (r 1, r 2, … r n, s 1, s 2, … s n )  S consists of attributes (s 1, s 2, … s n )  In other words, S has some subset of R’s attributes  Notation: R ÷ S

8 Division  Result contains:  Tuples for which the attribute values in R are equal to those in S  Attributes that exist in R, but not in S  Easier to show by example

9 Division (Relation R) addresslastContacted contactPhoneNumber numberTypecontactName 111 Great Street 1 day ago 555 5555CellPhil 8 Get Out of Here Way Last week 555 7777WorkBob 7 RUN! Drive 2 years ago 555 8888CellOctavio

10 Division (Relation S) numberType Cell

11 Division (R ÷ S) addresslastContacted contactPhoneNumber contactName 111 Great Street 1 day ago 555 5555Phil 7 RUN! Drive 2 years ago 555 8888Octavio

12 Division (Relation R) bandNamealbumgenre SepulturaChaos A.D.Thrash Devin TownsendKiProg Devin TownsendDeconstructionDeath metal GwarBattle MaximusThrash Cannibal CorpseThe BleedingDeath metal Pain of SalvationRemedy LaneProg GhoulManiaxeDeath metal Seventh WonderMercy FallsProg

13 Division (Relation S) genre Death metal Prog

14 Division (R ÷ S) bandNamealbum Devin TownsendKi Devin TownsendDeconstruction

15 Natural join  Returns all combinations of tuples between two relations that are equal on their common attribute names  Notation: R ⋈ S

16 Natural join (Relation R) guitarModelyear JEM7VWH2006 Music Man JPX72009 Stratocaster1954 Omen2008 PGM3012001 Jaguar1962 Les Paul1952

17 Natural join (Relation S) manufacturerguitarModel IbanezJEM7VWH Ernie BallMusic Man JPX7 FenderStratocaster SchecterOmen IbanezPGM301 FenderJaguar GibsonLes Paul

18 Natural join (R ⋈ S) manufacturerguitarModelyear IbanezJEM7VWH2006 Ernie BallMusic Man JPX72009 FenderStratocaster1954 SchecterOmen2008 IbanezPGM3012001 FenderJaguar1962 GibsonLes Paul1952

19 Joins in general  Joins are very important  There are more than one type of join  Big piece of relating relations/tables to one another in reality

20 Relational algebra expressions  All these operation can be strung together  Best to imagine each operation as functions that output a relation  In other words:  S = π phoneNumber (R)  S is also a relation, and we can use that in other operations  σ phoneNumber=555 5555 (S)  Or:  σ phoneNumber=555 5555 (π phoneNumber (R))

21 Relational algebra expressions  Get the model of all guitars made in 2006 or later  π guitarModel (σ year >= 2006 (GuitarModel ⋈ Guitar Year))  List age of everybody with a 3.0 GPA  π age (σ GPA=3.0 (Grades))

22 Combining expressions  Very similar to the kinds of statements we’ll see later when it comes to databases  Stringing together and combining various queries


Download ppt "Relational Algebra Continued CMSC 461 Michael Wilson."

Similar presentations


Ads by Google