3UNION 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);
4Union 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
5INTERSECTION 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);
6SET 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);
12THETA Join Example: SELECT * FROM Faculty, Offering EQUI-JoinExample:SELECT * FROM Faculty, OfferingWHERE Faculty.FacSSM=Offering.FacSSN;
13Exercise 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’?
14Summary Binary Operation Operation from Set Theory Join Operation UNIONINTERSECTIONDIFFERENCECARTESIAN PRODUCTJoin OperationEqui-JoinNatural JoinTheta Join
15ReferenceMaterials 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