Step 1: Identify the Two Tables Needed. (Each Join Operation Involves Two Tables.)

Total Page:16

File Type:pdf, Size:1020Kb

Step 1: Identify the Two Tables Needed. (Each Join Operation Involves Two Tables.)

Join Operation

Step 1: Identify the two tables needed. (Each Join operation involves two tables.)

Exercise 1: If the information you need to answer a query is in four tables, how many join operations will you have to do to get the information you need? Answer: ______

Step 2: Cartesian Product Operation (X)

Example: Cartesian Product of EMPLOYEE table and DEPARTMENT Table The resulting number of attributes: # attributes in EMPLOYEE + # attributes in DEPT The answer is ______. The resulting number of tuples: # tuples in EMPLOYEE X # tuples in DEPT The answer is ______.

EMPLOYEE Lname SSN ... Superssn DNO Smith 123456789 ... 333445555 5 Wong 333445555 ... 888665555 5 English 453453453 ... 333445555 5 Narayan 666884444 ... 333445555 5 Borg 888665555 ... 1 Wallace 987654321 ... 888665555 4 Jabbar 987987987 ... 987654321 4 Zelaya 999887777 ... 987654321 4 DEPT Dname Dnumb MgrSSN MgrStartDate Headquaters 1 er 888665555 19-Jun-71 Administration 4 987654321 01-Jan-85 Research 5 333445555 22-May-78

CARTESIAN PRODUCT of EMPLOYEE and DEPT Lname SSN ... Superssn DNO Dname Dn MgrSSN MgrStartDate Smith 123456789 ... 333445555 5 Headquaters 1um 888665555 19-Jun-71 Wong 333445555 ... 888665555 5 Headquaters 1 888665555 19-Jun-71 English 453453453 ... 333445555 5 Headquaters 1 888665555 19-Jun-71 Narayan 666884444 ... 333445555 5 Headquaters 1 888665555 19-Jun-71 Borg 888665555 ... 1 Headquaters 1 888665555 19-Jun-71 Wallace 987654321 ... 888665555 4 Headquaters 1 888665555 19-Jun-71 Jabbar 987987987 ... 987654321 4 Headquaters 1 888665555 19-Jun-71 Zelaya 999887777 ... 987654321 4 Headquaters 1 888665555 19-Jun-71 Smith 123456789 ... 333445555 5 Administration 4 987654321 01-Jan-85 Wong 333445555 ... 888665555 5 Administration 4 987654321 01-Jan-85 English 453453453 ... 333445555 5 Administration 4 987654321 01-Jan-85 Narayan 666884444 ... 333445555 5 Administration 4 987654321 01-Jan-85 Borg 888665555 ... 1 Administration 4 987654321 01-Jan-85 Wallace 987654321 ... 888665555 4 Administration 4 987654321 01-Jan-85 Jabbar 987987987 ... 987654321 4 Administration 4 987654321 01-Jan-85 Zelaya 999887777 ... 987654321 4 Administration 4 987654321 01-Jan-85 Smith 123456789 ... 333445555 5 Research 5 333445555 22-May-78 Wong 333445555 ... 888665555 5 Research 5 333445555 22-May-78 English 453453453 ... 333445555 5 Research 5 333445555 22-May-78 Narayan 666884444 ... 333445555 5 Research 5 333445555 22-May-78 Borg 888665555 ... 1 Research 5 333445555 22-May-78 Wallace 987654321 ... 888665555 4 Research 5 333445555 22-May-78 Jabbar 987987987 ... 987654321 4 Research 5 333445555 22-May-78 Zelaya 999887777 ... 987654321 4 Research 5 333445555 22-May-78 Step 3: Specify a JOIN Condition (e.g., selection criteria with comparison of values of attributes between two tables) according to your query.

Exercise 2: If the query is to find the last names of employees who work for “Research” Department, the join condition is ______.

Exercise 3: If the query is to find the first name of all the department managers, the join condition is ______.

Step 4: Join Results: Based on the selection, keep only the tuples that meet the join condition, throw away all other tuples.

Join attributes must have the same domain Comparison operator can be : =, <, >, etc. (Theta Join)

If only equality comparison is involved (the most common comparisons in queries): Equijoin: Keep both of the two join attributes in the result Natural Join: Keep only the first of the two join attribute in the result (e.g., getting rid of the second join attributes).

Exercise 4: What will be the join result for finding the last names of employees who work for “Research” Department?

Recommended publications