0911-ESeibel

0911-ESeibel - Database Systems #6 Summary Author: Eduard...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Database Systems #6 Summary Author: Eduard Seibel Covered Topics 1. Theta, EQUI & NATURAL JOIN 2. Complete Set of R. A. Operations 3. DIVISION Operation 4. Grouping with Aggregation 5. Query examples 1. Theta, EQUI & NATURAL JOIN 09/11/08 The general case of the JOIN operation is called ThetaJOIN r s = (r x s) Examples: Relation: r Relation: s A B 1 2 C D 10 10 20 10 E a a b B 1. r A=C D < 15 s A B 1 2 2. r 15*B < D s A A B 1 2 2 C D 10 10 B 1 E a a E b 3. r A=C s C D 20 E a a b C D 10 10 20 EQUI JOIN is a JOIN operation with equality comparsions only (see exaple 3. above) NATURAL JOIN joins two realtions by using overlapping attributes. Corresponding attributes have the same names in both relations. It is a implizit JOIN without specifing explicitly the JOINcondition. Example: Relation: r Relation: s A B 1 2 4 1 2 C D a a b a b B D 1 a 3 a 1 a 2 b 3 b E r * s ( = r r.B=s.B r.D=s.D s ) A B 1 1 1 1 2 C D a a a a b E Theta JOIN EQUI JOIN NATURAL JOIN 2. Complete Set of R. A. Operations The set of operations including (Projection), (Selection), (Difference), (Rename), (Union) and x (Cartesian Product) is called a complete set, because any other R. A. expression can be expressed by combination of these five operations. (Slide 644) Example: Do we need Intersection? No, we can derive it from these five operations. s r s = (r s) (r s) (s r) r 3. DIVISION Operation The devision operation is applied tot wo relations. R(Z) : S(X), where X is a subset of Z. Let Y = Z Y (and hence Z = X Y); that is, let Y be the set of attributes of R that are not attributes of S. The Result result of DIVISION is a relation T(Y) that includes a tuple t if tuples tR appear in R with tR [Y] = t, and with tR [X] = tS for every tuple ts in S. (slide 645) Example 1: Relation r Relation s r : s A B 1 2 3 1 1 1 3 4 6 1 2 B 1 2 A 1 2 Example 2: Relation r Relation s r : s A B a a a a a a a a C D a a b a b a b b E 1 1 1 1 3 1 1 1 D E a 1 b 1 A B C a a For what it is useful? For example to get all employees who are working in certain projects (more than one projcet). (see slide 646) 4. Grouping with Aggregation Used to send statistical queries that summarize information from the data base tupeles or collection of tuples (grouping). ga(Ai)(r) r: R (A1, A2, A3, ..., An) a = {MAX, MIN, AVG, SUM, CNT} Examples: Relation r gSUM(C)(r) gSUM(C), COUNT(A)(r) It is also possible to group the tuples by certain attributes first and then apply aggregate operations. Examples: we use the same realtion r (see above) This should be A,B A B C 7 7 3 10 SUM( C ) 27 SUM( C ) 27 COUNT( A ) 4 A gSUM(C)(r) A gSUM(C)(r) 5. Query examples A COUNT( C ) 14 13 A B SUM( C ) 7 7 13 Query 1: Find all the names and addresses oft all the employees who work for the ,Research` department. Fname, Minit, Lname, Address [ Dname=`Research` (EMPLOYEE Dno = Dnumber DEPARTMENT) ] Query 2: Find all the names oft all employees who have no dependents. Fname, Minit, Lname [( Ssn(EMPLOYEE) Essn(Dependent) ) * EMPLOYEE] or Fname, Minit, Lname (EMPLOYEE) Fname, Minit, Lname (EMPLOYEE Ssn = Essn DEPENDENT) ...
View Full Document

Ask a homework question - tutors are online