Presentation is loading. Please wait.

Presentation is loading. Please wait.

Relational Databases Relational Algebra (1) Select, project, join.

Similar presentations


Presentation on theme: "Relational Databases Relational Algebra (1) Select, project, join."— Presentation transcript:

1 Relational Databases Relational Algebra (1) Select, project, join

2 Relational Algebra (1) Query (expression) on set of relations produces relation as a result

3 Examples: simple college admissions database
Relational Algebra (1) Examples: simple college admissions database College(cName,state,enrollment) Student(sID,sName,GPA,sizeHS) Apply(sID,cName,major,decision) College Student Apply cName state enr sID sName GPA HS sID cName major dec

4 Simplest query: relation name Use operators to filter, slice, combine
Relational Algebra (1) Simplest query: relation name Use operators to filter, slice, combine College Student Apply cName state enr sID sName GPA HS sID cName major dec

5 Select operator: picks certain rows
Relational Algebra (1) Select operator: picks certain rows Students with GPA>3.7 Students with GPA>3.7 and HS<1000 Applications to Stanford CS major College Student Apply cName state enr sID sName GPA HS sID cName major dec

6 Project operator: picks certain columns
Relational Algebra (1) Project operator: picks certain columns ID and decision of all applications College Student Apply cName state enr sID sName GPA HS sID cName major dec

7 To pick both rows and columns…
Relational Algebra (1) To pick both rows and columns… ID and name of students with GPA>3.7 College Student Apply cName state enr sID sName GPA HS sID cName major dec

8 Relational Algebra (1) Duplicates
List of application majors and decisions College Student Apply cName state enr sID sName GPA HS sID cName major dec

9 Cross-product: combine two relations (a.k.a. Cartesian product)
Relational Algebra (1) Cross-product: combine two relations (a.k.a. Cartesian product) College Student Apply cName state enr sID sName GPA HS sID cName major dec

10 Cross-product: combine two relations (a.k.a. Cartesian product)
Relational Algebra (1) Cross-product: combine two relations (a.k.a. Cartesian product) Names and GPAs of students with HS>1000 who applied to CS and were rejected College Student Apply cName state enr sID sName GPA HS sID cName major dec

11 Relational Algebra (1) Natural Join
Enforce equality on all attributes with same name Eliminate one copy of duplicate attributes College Student Apply cName state enr sID sName GPA HS sID cName major dec

12 Relational Algebra (1) Natural Join
Names and GPAs of students with HS>1000 who applied to CS and were rejected Names and GPAs of students with HS>1000 who applied to CS at college with enr>20,000 and were rejected College Student Apply cName state enr sID sName GPA HS sID cName major dec

13 Relational Algebra (1) Natural Join College Student Apply cName state
enr sID sName GPA HS sID cName major dec

14 Relational Algebra (1) Theta Join Basic operation implemented in DBMS
Term “join” often means theta join College Student Apply cName state enr sID sName GPA HS sID cName major dec

15 Relational Algebra (1) Query (expression) on set of relations produces relation as a result Simplest query: relation name Use operators to filter, slice, combine Operators so far: select, project, cross-product, natural join, theta join


Download ppt "Relational Databases Relational Algebra (1) Select, project, join."

Similar presentations


Ads by Google