1 Problem Session 1 Products and Joins. 2 Outline uAnnouncements uSynopsis of Last Week uProducts and Joins – formal expressions, examples uProducts and.

Slides:



Advertisements
Similar presentations
Sample MQP Projects Murali Mani
Advertisements

Copyright © 2004 Pearson Education, Inc.. Chapter 15 Algorithms for Query Processing and Optimization.
1 Relational Algebra Basic Operations Algebra of Bags.
IS698: Database Management Min Song IS NJIT. The Relational Data Model.
1 Relational Algebra 1 Basic Operations. 2 What is an “Algebra” uMathematical system consisting of: wOperands --- variables or values from which new values.
1 Relational Algebra* and Tuple Calculus * The slides in this lecture are adapted from slides used in Standford's CS145 course.
Tallahassee, Florida, 2014 COP4710 Database Systems Relational Algebra Fall 2014.
SQL Group Members: Shijun Shen Xia Tang Sixin Qiang.
1 Introduction to SQL Select-From-Where Statements Multirelation Queries Subqueries.
1 Relational Algebra. Motivation Write a Java program Translate it into a program in assembly language Execute the assembly language program As a rough.
Relational Databases for Querying XML Documents: Limitations & Opportunities VLDB`99 Shanmugasundaram, J., Tufte, K., He, G., Zhang, C., DeWitt, D., Naughton,
CS411 Database Systems Kazuhiro Minami 06: SQL. Join Expressions.
1 Database Systems Relations as Bags Grouping and Aggregation Database Modification.
Fall 2001Arthur Keller – CS 1808–1 Schedule Today Oct. 18 (TH) Schemas, Views. u Read Sections u Project Part 3 extended to Oct. 23 (T). Oct.
Winter 2002Arthur Keller – CS 1808–1 Schedule Today: Jan. 29 (T) u Modifications, Schemas, Views. u Read Sections Assignment 3 due. Jan. 31 (TH)
Winter 2002Judy Cushing8–1 Schedule Jan. 30 (Wed) u Modifications, Schemas, Views. Read Sections This Week (Feb 4ff) u Constraints Read Sections.
1 Unified Modeling Language Classes Associations Aggregations.
Winter 2002Arthur Keller – CS 18018–1 Schedule Today: Mar. 12 (T) u Semistructured Data, XML, XQuery. u Read Sections Assignment 8 due. Mar. 14.
1 Problem Session 4 Project 1 Help Yusheng Yang Stanford University 10/22/2007 CS145 Autumn 2007.
Winter 2002Arthur Keller – CS 1807–1 Schedule Today: Jan. 24 (TH) u Subqueries, Grouping and Aggregation. u Read Sections Project Part 2 due.
1 Problem Session 5 Midterm Review Yusheng Yang Stanford University 10/29/2007 CS145 Autumn 2007.
Relational Databases Relational Algebra (2)
4/20/2017.
Relational Algebra Basic Operations Algebra of Bags.
CSCE 520- Relational Data Model Lecture 2. Relational Data Model The following slides are reused by the permission of the author, J. Ullman, from the.
Databases 1 First lecture. Informations Lecture: Monday 12:15-13:45 (3.716) Practice: Thursday 10:15-11:45 (2-519) Website of the course:
Constraints on Relations Foreign Keys Local and Global Constraints Triggers Following lecture slides are modified from Jeff Ullman’s slides
1 CS1368 Introduction* Relational Model, Schemas, SQL Semistructured Model, XML * The slides in this lecture are adapted from slides used in Standford's.
CSE314 Database Systems The Relational Algebra and Relational Calculus Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
RELATIONAL DATA MODEL 1. 2 What is a Data Model? 1.Mathematical representation of data. wExamples: relational model = tables; semistructured model = trees/graphs.
1 Relational Algebra Basic Operations Algebra of Bags.
1 Lecture 2 Relational Algebra Based on
Operations in the Relational Model COP 4720 Lecture 8 Lecture Notes.
CSCE 520- Relational Data Model Lecture 2. Oracle login Login from the linux lab or ssh to one of the linux servers using your cse username and password.
1 Lecture 6 Introduction to SQL part 4 Slides from
Relational Algebra BASIC OPERATIONS 1 DATABASE SYSTEMS AND CONCEPTS, CSCI 3030U, UOIT, COURSE INSTRUCTOR: JAREK SZLICHTA.
1 Announcements Reading for next week: Chapter 4 Your first homework will be assigned as soon as your database accounts have been set up.  Expect an .
CS 405G: Introduction to Database Systems Relations.
The Relational Model of Data Prof. Yin-Fu Huang CSIE, NYUST Chapter 2.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 18 A First Course in Database Systems.
1 Introduction to Database Systems, CS420 Relational Algebra.
Relational Algebra COMP3211 Advanced Databases Nicholas Gibbins
1 Relational Algebra & SQL Query Formulation Exercise.
Algebra 1 Section 4.2 Graph linear equation using tables The solution to an equation in two variables is a set of ordered pairs that makes it true. Is.
Select-From-Where Statements Multirelation Queries Subqueries
CPSC-310 Database Systems
Summary of Relational Algebra
CS 440 Database Management Systems
Database Design and Programming
Basic Operations Algebra of Bags
Logic as a Query Language: from Frege to XML
CPSC-310 Database Systems
Schedule Today: Jan. 28 (Mon) Jan. 30 (Wed) Next Week Assignments !!
COMP3017 Advanced Databases
COP4710 Database Systems Relational Algebra.
Relational Algebra and SQL
Introduction to Database Systems, CS420
CS 440 Database Management Systems
Relational Algebra 461 The slides for this text are organized into chapters. This lecture covers relational algebra, from Chapter 4. The relational calculus.
CPSC-310 Database Systems
Relational Databases Relational Algebra (2)
CPSC-310 Database Systems
Basic Operations Algebra of Bags
Where are we? Until now: Modeling databases (ODL, E/R): all about the schema Now: Manipulating the data: queries, updates, SQL Then: looking inside -
2/18/2019.
Syllabus Introduction Website Management Systems
CMSC-461 Database Management Systems
Headline will go here… 2 lines preferred
Instructor: Zhe He Department of Computer Science
Select-From-Where Statements Multirelation Queries Subqueries
Presentation transcript:

1 Problem Session 1 Products and Joins

2 Outline uAnnouncements uSynopsis of Last Week uProducts and Joins – formal expressions, examples uProducts and Joins – sample problems uQ&A

3 Announcements uMake sure you’re on the CS145 Coursework site by today uGradiance - one due Mon 10/8, two due Wed 10/10 uChallenge Problems #1 due Mon 10/8 wCorrection: #2 – can use union, intersection, difference as well wSubmit directly through Coursework (text in Assignments preferred, though.doc or.pdf in Drop Box acceptable) uAlways your questions to the staff list!

4 Synopsis of Last Week uData model: general conceptual way of structuring data wRelational model = tables (e.g., SQL) wSemistructured model = trees/graphs (e.g., XML) uSchema: structure of a particular relation or database under a certain data model uXML: language for semistructured model. DTD describes the structure. uRelational Algebra: algebra operating on relations. Prelude to SQL. uSQL: select-from-where

5 Products and Joins uProduct: R1 X R2 = {(t1, t2) : t1 in R1 and t2 in R2}  Theta Join: R1 ⋈ C R2 = σ C (R1 X R2)  Natural Join: R1 ⋈ R2 = π schema(R1) SETUNION schema(R2) (R1 ⋈ R1.A=R2.A and R1.B=R2.B and… R2)

6 Example: Product R1(A,B ) R2(B,C ) R3(A,R1.B,R2.B,C ) R3 := R1 X R2

7 Example: Theta Join R1(A,B ) R2(B,C ) R3 := R1 ⋈ R1.B=R2.B R2 R3(A,R1.B,R2.B,C )

8 Example: Natural Join R1(A,B ) R2(B,C ) R3 := R1 ⋈ R2 R3(A,R1.B,R2.B,C )

9 Sample Problem #1 Drinkers(name, addr, phone) Likes(drinker, beer) Find names and addresses of all drinkers who like Bud.

10 Sample Problem #1 Drinkers(name, addr, phone) Likes(drinker, beer) Find names and addresses of all drinkers who like Bud. Drinkers Likes σ name=drinker σ beer=‘Bud’ π name, addr X uMethod 1: filter, then concatenate uQuestion: how would you write this in SQL? uOne Possible Answer: SELECT name, addr FROM Drinkers, ( SELECT * FROM Likes WHERE beer = ‘Bud’) WHERE name = drinker;

11 Sample Problem #1 Drinkers(name, addr, phone) Likes(drinker, beer) Find names and addresses of all drinkers who like Bud. Drinkers Likes σ name=drinker π name, addr X uMethod 2: concatenate, then filter uQuestion: how would you write this in SQL? uOne Possible Answer: SELECT name, addr FROM Drinkers, Likes WHERE name = drinker AND beer = ‘Bud’; AND beer=‘Bud’

12 Sample Problem #2 Drinkers(name, addr, phone) Find names of all pairs of drinkers who live at the same address.

13 Sample Problem #2 Drinkers(name, addr, phone) Find names of all pairs of drinkers who live at the same address. Drinkers σ name<name1 π name, name1 uComparing drinkers with other drinkers, so reuse and rename uNatural join contains tuples (name, name1, addr, phone, phone1) such that both drinkers live at this address uSelect condition ensures no duplicates uExercise: SQL translation? ρ D(name1, addr, phone1) Drinkers ⋈

14 Q&A uWhat’s the difference between the relational and semistructured models? wSee first lecture. Basically, relational = rigid tables and semistructured = flexible graphs. uThe semistructured model is supposed to be flexible, but can’t you represent everything in relational algebra if you plan far enough ahead? wWell, in reality there are a lot of things that you can’t possibly plan ahead for, so you need the semistructured model for that.