3 UNION operation Example SQL for previous example Fig 6.4: Suppose names of people are distinctARESULT=STUDENT INSTRUCTORBSQL for previous example Fig 6.4:(SELECT Fn, Ln FROM STUDENT)UNION(SELECT Fname, Lname FROM INSTRUCTOR);
4 Union Compatibility Requirement for the traditional set operators Strong requirementSame number of columnsEach corresponding column is compatiblePositional correspondenceHow are rows compared?- Chapter 3 material: present again for review if desired- Can instead present material in Chapter 4 and skip when initially covering chapter 3- Join: compares rows on the join column(s)- Traditional set operators compare on all columnsStrong requirement:- Usually on identical tables (geographically dispersed tables)- Compatible columns: data types are comparable (numbers cannot be comparedto strings)- Positional: 1st column of table A to 1st column of table B, 2nd column etcCan be applied to similar tables (faculty and student) by removing columns before traditional set operator
5 INTERSECTION operation ExampleSuppose names of people are distinctABRESULT=STUDENT INSTRUCTORSQL for previous example Fig 6.4:(SELECT Fn, Ln FROM STUDENT)INTERSECT(SELECT Fname, Lname FROM INSTRUCTOR);
6 SET DIFFERENCE operation ExampleSTUDENT - INSTRUCTORINSTRUCTOR - STUDENTSuppose names of people are distinct(d) RESULT=INSTRUCTOR - STUDENTAB(e) RESULT=STUDENT - INSTRUCTORBSQL for previous example Fig 6.4:(SELECT Fn, Ln FROM STUDENT)MINUS(SELECT Fname, Lname FROM INSTRUCTOR);
12 THETA Join Example: SELECT * FROM Faculty, Offering EQUI-JoinExample:SELECT * FROM Faculty, OfferingWHERE Faculty.FacSSM=Offering.FacSSN;
13 Exercise 2 Department Student Faculty DnoDnameDHeadSsnLocationSIDSnameDnoSAgeStudentFSsnFnameDnoFAgeFacultyWrite Relational Algebra and SQL queries for following questions:What are the names of students who are from department ‘Computer Science’?What are the names of faculties who are younger than a student?What are the names of faculties who works in ‘Keller Hall’?
14 Summary Binary Operation Operation from Set Theory Join Operation UNIONINTERSECTIONDIFFERENCECARTESIAN PRODUCTJoin OperationEqui-JoinNatural JoinTheta Join
15 ReferenceMaterials in the slides are from Elmasri, Navathe, Fundamentals of Database Systems, 6th, Addison Wesley and Michael V. Mannino, Database: Design, Application Development & Administration, Third Edition, McGraw Hill