Download presentation

Presentation is loading. Please wait.

Published byVivian Smallman Modified about 1 year ago

1
Binary Operations in Relational Algebra & SQL 1

2
Set Based: UNION, INTERSECTION, DIFFERENCE 2

3
UNION operation Example A RESULT=STUDENT INSTRUCTOR B SQL for previous example Fig 6.4: (SELECT Fn, Ln FROM STUDENT) UNION (SELECT Fname, Lname FROM INSTRUCTOR); Suppose names of people are distinct 3

4
Union Compatibility Requirement for the traditional set operators Strong requirement – Same number of columns – Each corresponding column is compatible – Positional correspondence 4

5
INTERSECTION operation Example RESULT=STUDENT INSTRUCTOR SQL for previous example Fig 6.4: (SELECT Fn, Ln FROM STUDENT) INTERSECT (SELECT Fname, Lname FROM INSTRUCTOR); AB Suppose names of people are distinct 5

6
SET DIFFERENCE operation Example B SQL for previous example Fig 6.4: (SELECT Fn, Ln FROM STUDENT) MINUS (SELECT Fname, Lname FROM INSTRUCTOR); (d) RESULT=INSTRUCTOR - STUDENT A B (e) RESULT=STUDENT - INSTRUCTOR INSTRUCTOR - STUDENT STUDENT - INSTRUCTOR Suppose names of people are distinct 6

7
CARTESIAN PRODUCT operation Example B SQL: SELECT * FROM Faculty, Student; Relational Algebra: RESULT= Faculty ✕ Student 7

8
EQUI-Join RESULT= Faculty (Faculty.FacSSM=Offering.FacSSN) Offering; SELECT * FROM Faculty, Offering WHERE Faculty.FacSSN=Offering.FacSSN; Example: EQUI-Join 8

9
Exercise 1 for Equi-Join 9 SQL query Result a.T1 (T1.P=T2.A) T2 b.T1 (T1.Q=T2.B) T2

10
NATURAL-Join RESULT= Faculty * Offering; SELECT * FROM EMPLOYEE NATURAL JOIN DEPARTMENT Example: 10

11
THETA Join RESULT=Car {CarPrice>BoatPrice} Boat; Result=R1 {Condition} R2; Condition: {, =, ≤, ≥, ≠}; EquiJoin when “=“. SELECT * FROM Car, Boat WHERE CarPrice>BoatPrice; Example: 11

12
THETA Join SELECT * FROM Faculty, Offering WHERE Faculty.FacSSM=Offering.FacSSN; Example: EQUI-Join Theta-Join 12

13
Exercise 2 DnoDnameDHeadSsnLocation 13 Department SIDSnameDnoSAge Student FSsnFnameDnoFAge Faculty Write 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 UNION INTERSECTION DIFFERENCE CARTESIAN PRODUCT – Join Operation Equi-Join Natural Join Theta Join 14

15
Reference Materials 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 15

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google