Presentation is loading. Please wait.

Presentation is loading. Please wait.

Relational Algebra at a Glance

Similar presentations


Presentation on theme: "Relational Algebra at a Glance"— Presentation transcript:

1 Relational Algebra at a Glance
Operators: sets as input, new set as output Basic Set Operators union, intersection, difference, but no complement. Selection: s Projection: p Cartesian Product: X Joins (natural,equi-join, theta join, semi-join) Renaming: r

2 Set Operations Binary operations
Result is table(set) with same attributes Watch out for naming of attributes in resulting relation. Union: all tuples in R1 or R2 Intersection: all tuples in R1 and R2 Difference: all tuples in R1 and not in R2 No complement. Why? Bags later.

3 Selection Produce a subset of the tuples in a relation which satisfy a given condition Unary operation… returns set with same attributes, but ‘selects’ rows Use and, or, not, >, <… to build condition Find all employees with salary more than $40,000:

4 Find all employees with salary more than $40,000.

5 Projection Unary operation, selects columns
Eliminates duplicate tuples Example: project social-security number and names.

6

7 Cartesian Product Binary Operation
Result is tuples combining any element of R1 with any element of R2, for R1 X R2 Schema is union of Schema(R1) & Schema(R2)

8

9 Join (Natural) Most important, expensive and exciting.
Combines two relations, selecting only related tuples Equivalent to a cross product followed by selection Resulting schema has all attributes of the two relations, but one copy of join condition attributes

10

11 Other Joins and Renaming
Theta join: the join involves a predicate R S Semi-join: the attributes of one relation are included in the other. Renaming:

12 Complex Queries Product ( pname, price, category, maker)
Purchase (buyer, seller, store, product) Company (cname, stock price, country) Person( per-name, phone number, city) Find phone numbers of people who bought gizmos from Fred. Find telephony products that somebody bought

13 Exercises Product ( pname, price, category, maker)
Purchase (buyer, seller, store, product) Company (cname, stock price, country) Person( per-name, phone number, city) Ex #1: Find people who bought telephony products. Ex #2: Find names of people who bought American products Ex #3: Find names of people who bought American products and did not buy French products Ex #4: Find names of people who bought American products and they live in Seattle. Ex #5: Find people who bought stuff from Joe or bought products from a company whose stock prices is more than $50.

14 Operations on Bags (and why we care)
Basic operations: Projection Selection Union Intersection Set difference Cartesian product Join (natural join, theta join)


Download ppt "Relational Algebra at a Glance"

Similar presentations


Ads by Google