1 / 15

Binary Operations in Relational Algebra & SQL

Binary Operations in Relational Algebra & SQL. Set Based: UNION, INTERSECTION, DIFFERENCE. UNION operation. Example. A. RESULT=STUDENT INSTRUCTOR. B. Suppose names of people are distinct. SQL for previous example Fig 6.4: (SELECT Fn, Ln FROM STUDENT) UNION

gomer
Download Presentation

Binary Operations in Relational Algebra & SQL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Binary Operationsin Relational Algebra & SQL

  2. Set Based: UNION, INTERSECTION, DIFFERENCE

  3. UNION operation Example A RESULT=STUDENT INSTRUCTOR B Suppose names of people are distinct SQL 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 requirement • Same number of columns • Each corresponding column is compatible • Positional correspondence

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

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

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

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

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

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

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

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

  13. Exercise 2 Department Student 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

  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

More Related