Binary Operations in Relational Algebra & SQL

Slides:



Advertisements
Similar presentations
Chapter 6 The Relational Algebra
Advertisements

Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 The Relational Algebra.
พีชคณิตแบบสัมพันธ์ (Relational Algebra) บทที่ 3 อ. ดร. ชุรี เตชะวุฒิ CS (204)321 ระบบฐานข้อมูล 1 (Database System I)
Copyright © 2004 Pearson Education, Inc.. Chapter 15 Algorithms for Query Processing and Optimization.
Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield.
Copyright © 2004 Ramez Elmasri and Shamkant Navathe Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 15-1 Query Processing and.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 (Continued) The Relational Algebra and Calculus.
Database Systems Chapter 6 ITM Relational Algebra The basic set of operations for the relational model is the relational algebra. –enable the specification.
Copyright © 2004 Pearson Education, Inc.. Chapter 6 The Relational Algebra and Relational Calculus.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
Copyright © 2004 Pearson Education, Inc.. Chapter 8 SQL-99: Schema Definition, Basic Constraints, and Queries.
Relational Algebra Chapter 4 - part I. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
Chapter 11.1 and 11.2 Data Manipulation: Relational Algebra and SQL Brian Cobarrubia Introduction to Database Management Systems October 4, 2007.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 The Relational Algebra and Calculus.
Copyright © Curt Hill The Relational Algebra What operations can be done?
Relational Algebra Example Database Application (COMPANY) Relational Algebra –Unary Relational Operations –Relational Algebra Operations From Set Theory.
Copyright © 2004 Pearson Education, Inc.. Chapter 15 Algorithms for Query Processing and Optimization.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 The Relational Algebra and Calculus.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 The Relational Algebra.
CSE314 Database Systems The Relational Algebra and Relational Calculus Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
Lecture 15: Relational Algebra
Relational Algebra References: Databases Illuminated by Catherine Ricardo, published by Jones and Bartlett in 2004 Fundamentals of Relational Databases.
METU Department of Computer Eng Ceng 302 Introduction to DBMS The Relational Algebra by Pinar Senkul resources: mostly froom Elmasri, Navathe and other.
M Taimoor Khan Course Objectives 1) Basic Concepts 2) Tools 3) Database architecture and design 4) Flow of data (DFDs)
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
Oracle DML Dr. Bernard Chen Ph.D. University of Central Arkansas.
Fundamentals of Database Systems Fourth Edition El Masri & Navathe Instructor: Mr. Ahmed Al Astal Chapter 6 The Relational Algebra University Of Palestine.
RELATIONAL ALGEBRA CHAPTER 6 1. LECTURE OUTLINE  Unary Relational Operations: SELECT and PROJECT  Relational Algebra Operations from Set Theory  Binary.
Unit 4 Queries and Joins. Key Concepts Using the SELECT statement Statement clauses Subqueries Multiple table statements Using table pseudonyms Inner.
The Relational Algebra and Calculus
October 9, Announcements Exam Tuesday in class –Closed book Program 2 due Friday –Turn in using D2L dropbox –Only turn in the 4 files specified.
Chapter 6 The Relational Algebra Copyright © 2004 Ramez Elmasri and Shamkant Navathe.
Slide 6- 1 CARTESIAN (or cross) Product Operation Defines a relation Q that is the concatenation of every tuple of relation R with every tuple of relation.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
DatabaseIM ISU1 Fundamentals of Database Systems Chapter 6 The Relational Algebra.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 The Relational Algebra.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 Part a The Relational Algebra and Relational Calculus Hours 1,2.
Al-Maarefa College for Science and Technology INFO 232: Database systems Chapter 3 “part 2” The Relational Algebra and Calculus Instructor Ms. Arwa Binsaleh.
Relational Algebra MBAD 613 R. Nakatsu. Relational Data Manipulation Language Query-by-Example; Query-by-Form Transform-Oriented Languages Relational.
Advanced Relational Algebra & SQL (Part1 )
CpSc 462/662: Database Management Systems (DBMS) (TEXNH Approach) Relational Algebra James Wang.
Relational Algebra Relational Calculus
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
Chapter 15 Algorithms for Query Processing and Optimization Copyright © 2004 Pearson Education, Inc.
Dr. Mohamed Hegazi1 The Relational Algebra and Relational Calculus.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
Copyright © 2004 Pearson Education, Inc.. Chapter 6 The Relational Algebra and Relational Calculus.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 6- 1.
Chapter 6 The Relational Algebra Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
1 CSE 480: Database Systems Lecture 16: Relational Algebra.
Relational Algebra COMP3211 Advanced Databases Nicholas Gibbins
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus تنبيه : شرائح العرض.
Relational Algebra National University of Computer and Emerging Sciences Lecture # 6 June 30,2012.
The Relational Algebra and Relational Calculus
slides by: Pavle Morgan & Hui Ma
The Relational Algebra and Calculus
COMP3017 Advanced Databases
CS4432: Database Systems II
Fundamental of Database Systems
The Relational Algebra and Relational Calculus
Elmasri/Navathe, Fundamentals of Database Systems, 4th Edition
Relational Algebra 461 The slides for this text are organized into chapters. This lecture covers relational algebra, from Chapter 4. The relational calculus.
LECTURE 3: Relational Algebra
More Relational Algebra
SQL: Set Operations & Nested Queries. Presented by: Dr. Samir Tartir
Chapter 4 Relational Algebra
Presentation transcript:

Binary Operations in Relational Algebra & SQL

Set Based: UNION, INTERSECTION, DIFFERENCE

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

Union Compatibility Requirement for the traditional set operators Strong requirement Same number of columns Each corresponding column is compatible Positional correspondence How 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 columns Strong requirement: - Usually on identical tables (geographically dispersed tables) - Compatible columns: data types are comparable (numbers cannot be compared to strings) - Positional: 1st column of table A to 1st column of table B, 2nd column etc Can be applied to similar tables (faculty and student) by removing columns before traditional set operator

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);

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

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

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

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

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

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

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

Exercise 2 Department Student Faculty Dno Dname DHeadSsn Location SID Sname Dno SAge Student FSsn Fname Dno FAge 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’?

Summary Binary Operation Operation from Set Theory Join Operation UNION INTERSECTION DIFFERENCE CARTESIAN PRODUCT Join Operation Equi-Join Natural Join Theta Join

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