CS 480: Database Systems Lecture 9 February 4, 2013.

Slides:



Advertisements
Similar presentations
Gong show Stefano Ceri Politecnico di Milano. Higher order data mining Given a database, give me all the results to the interesting queries –Needs to.
Advertisements

CS411 Database Systems Kazuhiro Minami 06: SQL. SQL = Structured Query Language Standard language for querying and manipulating data Has similar capabilities.
COMP 5138 Relational Database Management Systems Semester 2, 2007 Lecture 5A Relational Algebra.
1 Relational Algebra* and Tuple Calculus * The slides in this lecture are adapted from slides used in Standford's CS145 course.
SQL Group Members: Shijun Shen Xia Tang Sixin Qiang.
SQL Queries Principal form: SELECT desired attributes FROM tuple variables –– range over relations WHERE condition about tuple variables; Running example.
Dale Roberts 1 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
SQL CSET 3300.
CS411 Database Systems Kazuhiro Minami 06: SQL. Join Expressions.
1 Database Systems Relations as Bags Grouping and Aggregation Database Modification.
1 Introduction to SQL Multirelation Queries Subqueries Slides are reused by the approval of Jeffrey Ullman’s.
Spring 2003 ECE569 Lecture 02.1 ECE 569 Database System Engineering Spring 2003 Yanyong Zhang
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #3.
Cursors in Pl/SQL Database 1. Practice. Sample Database The schema of the sample database is the following: Drinkers (name, occupation, birthday, salary)
Optimization of Relational Algebra Expressions Database I.
1 Database Systems Defining Database Schema Views.
Databases 1 Second lecture.
1 Views, Indexes Virtual and Materialized Views Speeding Accesses to Data.
1 Introduction to SQL Database Systems. 2 Why SQL? SQL is a very-high-level language, in which the programmer is able to avoid specifying a lot of data-manipulation.
1 CSE544 Monday April 26, Announcements Project Milestone –Due today Next paper: On the Unusual Effectiveness of Logic in Computer Science –Need.
1 Lecture 6 Introduction to SQL part 4 Slides from
Himanshu GuptaCSE 532-SQL-1 SQL. Himanshu GuptaCSE 532-SQL-2 Why SQL? SQL is a very-high-level language, in which the programmer is able to avoid specifying.
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.
Hoi Le. Why database? Spreadsheet is not good to: Store very large information Efficiently update data Use in multi-user mode Hoi Le2.
1 Introduction to Database Systems, CS420 SQL Views and Indexes.
Databases 2 On-Line Application Processing: Warehousing, Data Cubes, Data Mining.
1 Relational Algebra & SQL Query Formulation Exercise.
1 Introduction to Database Systems, CS420 SQL JOIN, Aggregate, Grouping, HAVING and DML Clauses.
Select-From-Where Statements Multirelation Queries Subqueries
On-Line Application Processing
CS 440 Database Management Systems
Virtual and Materialized Views Speeding Accesses to Data
Logic as a Query Language: from Frege to XML
CPSC-310 Database Systems
Slides are reused by the approval of Jeffrey Ullman’s
CPSC-310 Database Systems
CS 480: Database Systems Lecture 16 February 20,2013.
CS 480: Database Systems Lecture 17 February 22, 2013.
Outerjoins, Grouping/Aggregation Insert/Delete/Update
CS 480: Database Systems Lecture 13 February 13,2013.
Foreign Keys Local and Global Constraints Triggers
Databases : More about SQL
Relational Algebra and SQL
CPSC-310 Database Systems
Data Warehouse.
Example: R3 := R1 × R2 R3( A, R1.B, R2.B, C )‏ R1( A, B )‏ R2( B, C )‏ R3( A, R1.B, R2.B, C )‏
CS 480: Database Systems Lecture 15 February 18, 2013.
Schedule Today: Next After that Subqueries, Grouping and Aggregation.
Introduction to Database Systems, CS420
CS 480: Database Systems Lecture 8 February 1, 2013.
CPSC-608 Database Systems
CS 440 Database Management Systems
CPSC-608 Database Systems
CPSC-310 Database Systems
CPSC-310 Database Systems
CPSC-310 Database Systems
IST 210: Organization of Data
Relational Databases Relational Algebra (2)
CPSC-310 Database Systems
On-Line Application Processing
Virtual and Materialized Views Speeding Accesses to Data
CPSC-608 Database Systems
CPSC-608 Database Systems
More SQL Extended Relational Algebra Outerjoins, Grouping/Aggregation
Transactions, Views, Indexes
Microsoft Access Date.
Instructor: Zhe He Department of Computer Science
CSE544 Wednesday, March 29, 2006.
Select-From-Where Statements Multirelation Queries Subqueries
Presentation transcript:

CS 480: Database Systems Lecture 9 February 4, 2013

Examples #3 d-name d-city ba-name ba-city Frequents Drinker Bar Likes Serves All of them are many to many. Beer be-name type

Examples #3 d-name d-city ba-name ba-city Frequents Drinker Bar Likes Serves Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) One relation for each entity set Beer be-name type

Examples #3 d-name d-city ba-name ba-city Frequents Drinker Bar Likes Serves Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) One relation for each relationship set Beer be-name type

Example #3, Query #1 Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #1: Which bars serve a beer that Joe likes?

Example #3, Query #1 Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #1: Which bars serve a beer that Joe likes? Steps to take? Retrieve the beers that Joe likes. Find out which bars serve each of those beers. Extract the bar names for those bars.

Example #3, Query #1 Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #1: Which bars serve a beer that Joe likes? Steps to take? Retrieve the beers that Joe likes. Find out which bars serve each of those beers. Extract the bar names for those bars.

Example #3, Query #1 Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #1: Which bars serve a beer that Joe likes? Steps to take? Retrieve the beers that Joe likes. Find out which bars serve each of those beers. Extract the bar names for those bars.

Example #3, Query #1 Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #1: Which bars serve a beer that Joe likes? Steps to take? Retrieve the beers that Joe likes. Find out which bars serve each of those beers. Extract the bar names for those bars.

Example #3, Query #1 Πba-name(σd-name=‘Joe’(likes) serves) Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #1: Which bars serve a beer that Joe likes? Step 1: Retrieve the beers that Joe likes. Πba-name(σd-name=‘Joe’(likes) serves)

Example #3, Query #1 Πba-name(σd-name=‘Joe’(likes) serves) Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #1: Which bars serve a beer that Joe likes? Step 1: Retrieve the beers that Joe likes. Πba-name(σd-name=‘Joe’(likes) serves)

Example #3, Query #1 Πba-name(σd-name=‘Joe’(likes) serves) Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #1: Which bars serve a beer that Joe likes? Step 2: Find out which bars serve each of those beers. Πba-name(σd-name=‘Joe’(likes) serves)

Example #3, Query #1 Πba-name(σd-name=‘Joe’(likes) serves) Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #1: Which bars serve a beer that Joe likes? Step 2: Find out which bars serve each of those beers. Πba-name(σd-name=‘Joe’(likes) serves)

Example #3, Query #1 Πba-name(σd-name=‘Joe’(likes) serves) Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #1: Which bars serve a beer that Joe likes? Step 3: Extract the bar names for those bars. Πba-name(σd-name=‘Joe’(likes) serves)

Example #3, Query #1 Πba-name(σd-name=‘Joe’(likes) serves) Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #1: Which bars serve a beer that Joe likes? Step 3: Extract the bar names for those bars. Πba-name(σd-name=‘Joe’(likes) serves)

Example #3, Query #1 Πba-name(σd-name=‘Joe’(likes) serves) Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #1: Which bars serve a beer that Joe likes? Πba-name(σd-name=‘Joe’(likes) serves)

Example #3, Query #1 Πba-name(σd-name=‘Joe’(likes serves)) Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #1: Which bars serve a beer that Joe likes? Are these two queries equivalent? Πba-name(σd-name=‘Joe’(likes serves)) Πba-name(σd-name=‘Joe’(likes) serves)

Example #3, Query #2 Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #2: Which drinkers frequent all the bars that serve ‘Bud’?

Example #3, Query #2 Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #2: Which drinkers frequent all the bars that serve ‘Bud’? Steps to take? Compute all bars that serve Bud Find out all drinkers that frequent all of those

Example #3, Query #2 Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #2: Which drinkers frequent all the bars that serve ‘Bud’? Steps to take? Compute all bars that serve Bud Find out all drinkers that frequent all of those

Example #3, Query #2 Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #2: Which drinkers frequent all the bars that serve ‘Bud’? Steps to take? Compute all bars that serve Bud Find out all drinkers that frequent all of those

Example #3, Query #2 frequents  Πba-name(σbe-name=‘Bud’(serves)) Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #2: Which drinkers frequent all the bars that serve ‘Bud’? Step 1: Compute all bars that serve Bud frequents  Πba-name(σbe-name=‘Bud’(serves))

Example #3, Query #2 frequents  Πba-name(σbe-name=‘Bud’(serves)) Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #2: Which drinkers frequent all the bars that serve ‘Bud’? Step 1: Compute all bars that serve Bud frequents  Πba-name(σbe-name=‘Bud’(serves))

Example #3, Query #2 frequents  Πba-name(σbe-name=‘Bud’(serves)) Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #2: Which drinkers frequent all the bars that serve ‘Bud’? Step 1: Compute all bars that serve Bud frequents  Πba-name(σbe-name=‘Bud’(serves))

Example #3, Query #2 frequents  Πba-name(σbe-name=‘Bud’(serves)) Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #2: Which drinkers frequent all the bars that serve ‘Bud’? Step 2: Find out all drinkers that frequent all of those frequents  Πba-name(σbe-name=‘Bud’(serves))

Example #3, Query #2 frequents  Πba-name(σbe-name=‘Bud’(serves)) Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #2: Which drinkers frequent all the bars that serve ‘Bud’? Step 2: Find out all drinkers that frequent all of those frequents  Πba-name(σbe-name=‘Bud’(serves))

Example #3, Query #2 frequents  Πba-name(σbe-name=‘Bud’(serves)) Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #2: Which drinkers frequent all the bars that serve ‘Bud’? frequents  Πba-name(σbe-name=‘Bud’(serves))

Example #3, Query #2 Πd-name(frequents) – Πd-name ( Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #2: Which drinkers frequent all the bars that serve ‘Bud’? Middle line is pairs of (d-name,ba-name) such that the drinker does not frequent that bar. Join it with bottom line. Bars that serve Bud… Then you have drinkers that don’t frequent some bar that serves bud. Take out all of those with the top line and you get only drinkers that go to all bars that serve Bud. Alternative without division: Πd-name(frequents) – Πd-name ( ((Πd-name(drinker)  Πba-name(bar)) – frequents) Πba-name(σbe-name=‘Bud’(serves)))

Example #3, Query #2 Πd-name(frequents) – Πd-name ( Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #2: Which drinkers frequent all the bars that serve ‘Bud’? Middle line is pairs of (d-name,ba-name) such that the drinker does not frequent that bar. Join it with bottom line. Bars that serve Bud… Then you have drinkers that don’t frequent some bar that serves bud. Take out all of those with the top line and you get only drinkers that go to all bars that serve Bud. Alternative without division: Πd-name(frequents) – Πd-name ( ((Πd-name(drinker)  Πba-name(bar)) – frequents) Πba-name(σbe-name=‘Bud’(serves)))

Example #3, Query #2 Πd-name(frequents) – Πd-name ( Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #2: Which drinkers frequent all the bars that serve ‘Bud’? Middle line is pairs of (d-name,ba-name) such that the drinker does not frequent that bar. Join it with bottom line. Bars that serve Bud… Then you have drinkers that don’t frequent some bar that serves bud. Take out all of those with the top line and you get only drinkers that go to all bars that serve Bud. Alternative without division: Πd-name(frequents) – Πd-name ( ((Πd-name(drinker)  Πba-name(bar)) – frequents) Πba-name(σbe-name=‘Bud’(serves))) All possible drinker,bar pairs

Example #3, Query #2 Πd-name(frequents) – Πd-name ( Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #2: Which drinkers frequent all the bars that serve ‘Bud’? Middle line is pairs of (d-name,ba-name) such that the drinker does not frequent that bar. Join it with bottom line. Bars that serve Bud… Then you have drinkers that don’t frequent some bar that serves bud. Take out all of those with the top line and you get only drinkers that go to all bars that serve Bud. Alternative without division: Πd-name(frequents) – Πd-name ( ((Πd-name(drinker)  Πba-name(bar)) – frequents) Πba-name(σbe-name=‘Bud’(serves)))

Example #3, Query #2 Πd-name(frequents) – Πd-name ( Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #2: Which drinkers frequent all the bars that serve ‘Bud’? Middle line is pairs of (d-name,ba-name) such that the drinker does not frequent that bar. Join it with bottom line. Bars that serve Bud… Then you have drinkers that don’t frequent some bar that serves bud. Take out all of those with the top line and you get only drinkers that go to all bars that serve Bud. Alternative without division: Πd-name(frequents) – Πd-name ( ((Πd-name(drinker)  Πba-name(bar)) – frequents) Πba-name(σbe-name=‘Bud’(serves))) Drinkers with the bars that they don’t frequent.

Example #3, Query #2 Πd-name(frequents) – Πd-name ( Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #2: Which drinkers frequent all the bars that serve ‘Bud’? Middle line is pairs of (d-name,ba-name) such that the drinker does not frequent that bar. Join it with bottom line. Bars that serve Bud… Then you have drinkers that don’t frequent some bar that serves bud. Take out all of those with the top line and you get only drinkers that go to all bars that serve Bud. Alternative without division: Πd-name(frequents) – Πd-name ( ((Πd-name(drinker)  Πba-name(bar)) – frequents) Πba-name(σbe-name=‘Bud’(serves)))

Example #3, Query #2 Πd-name(frequents) – Πd-name ( Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #2: Which drinkers frequent all the bars that serve ‘Bud’? Middle line is pairs of (d-name,ba-name) such that the drinker does not frequent that bar. Join it with bottom line. Bars that serve Bud… Then you have drinkers that don’t frequent some bar that serves bud. Take out all of those with the top line and you get only drinkers that go to all bars that serve Bud. Alternative without division: Πd-name(frequents) – Πd-name ( ((Πd-name(drinker)  Πba-name(bar)) – frequents) Πba-name(σbe-name=‘Bud’(serves))) Drinkers with the bars that serve Bud that they don’t frequent.

Example #3, Query #2 Πd-name(frequents) – Πd-name ( Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #2: Which drinkers frequent all the bars that serve ‘Bud’? Middle line is pairs of (d-name,ba-name) such that the drinker does not frequent that bar. Join it with bottom line. Bars that serve Bud… Then you have drinkers that don’t frequent some bar that serves bud. Take out all of those with the top line and you get only drinkers that go to all bars that serve Bud. Alternative without division: Πd-name(frequents) – Πd-name ( ((Πd-name(drinker)  Πba-name(bar)) – frequents) Πba-name(σbe-name=‘Bud’(serves)))

Example #3, Query #2 Πd-name(frequents) – Πd-name ( Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #2: Which drinkers frequent all the bars that serve ‘Bud’? Middle line is pairs of (d-name,ba-name) such that the drinker does not frequent that bar. Join it with bottom line. Bars that serve Bud… Then you have drinkers that don’t frequent some bar that serves bud. Take out all of those with the top line and you get only drinkers that go to all bars that serve Bud. Alternative without division: Πd-name(frequents) – Πd-name ( ((Πd-name(drinker)  Πba-name(bar)) – frequents) Πba-name(σbe-name=‘Bud’(serves))) Drinkers that don’t frequent some bar that serves Bud.

Example #3, Query #2 Πd-name(frequents) – Πd-name ( Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #2: Which drinkers frequent all the bars that serve ‘Bud’? Middle line is pairs of (d-name,ba-name) such that the drinker does not frequent that bar. Join it with bottom line. Bars that serve Bud… Then you have drinkers that don’t frequent some bar that serves bud. Take out all of those with the top line and you get only drinkers that go to all bars that serve Bud. Alternative without division: Πd-name(frequents) – Πd-name ( ((Πd-name(drinker)  Πba-name(bar)) – frequents) Πba-name(σbe-name=‘Bud’(serves))) Drinkers that frequent all bars that serve ‘Bud’.

Example #3, Query #2 Πd-name(frequents) – Πd-name ( Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #2: Which drinkers frequent all the bars that serve ‘Bud’? Middle line is pairs of (d-name,ba-name) such that the drinker does not frequent that bar. Join it with bottom line. Bars that serve Bud… Then you have drinkers that don’t frequent some bar that serves bud. Take out all of those with the top line and you get only drinkers that go to all bars that serve Bud. Alternative without division: Πd-name(frequents) – Πd-name ( ((Πd-name(drinker)  Πba-name(bar)) – frequents) Πba-name(σbe-name=‘Bud’(serves)))

Example #3, Query #3 Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #3: Which drinkers frequent a bar that serves a beer they like?

Example #3, Query #3 Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #3: Which drinkers frequent a bar that serves a beer they like? Steps to take? Get drinkers with the beers they like and the bars serve those beers. Of those, also get only the bars that they also frequent. Extract the drinkers.

Example #3, Query #3 Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #3: Which drinkers frequent a bar that serves a beer they like? Steps to take? Get drinkers with the beers they like and the bars serve those beers. Of those, also get only the bars that they also frequent. Extract the drinkers.

Example #3, Query #3 Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #3: Which drinkers frequent a bar that serves a beer they like? Steps to take? Get drinkers with the beers they like and the bars serve those beers. Of those, also get only the bars that they also frequent. Extract the drinkers.

Example #3, Query #3 Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #3: Which drinkers frequent a bar that serves a beer they like? Steps to take? Get drinkers with the beers they like and the bars that serve those beers. Of those, also get only the bars that they also frequent. Extract the drinkers.

Example #3, Query #3 Πd-name(likes serves frequents) Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #3: Which drinkers frequent a bar that serves a beer they like? First join is drinker,beer,bar such that drinker likes a beer and the bar serves that beer. Second join strips out the triples that had a bar that the drinker does not frequent. Step 1: Get drinkers with the beers they like and the bars that serve those beers. Πd-name(likes serves frequents)

Example #3, Query #3 Πd-name(likes serves frequents) Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #3: Which drinkers frequent a bar that serves a beer they like? First join is drinker,beer,bar such that drinker likes a beer and the bar serves that beer. Second join strips out the triples that had a bar that the drinker does not frequent. Step 1: Get drinkers with the beers they like and the bars that serve those beers. Πd-name(likes serves frequents)

Example #3, Query #3 Πd-name(likes serves frequents) Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #3: Which drinkers frequent a bar that serves a beer they like? First join is drinker,beer,bar such that drinker likes a beer and the bar serves that beer. Second join strips out the triples that had a bar that the drinker does not frequent. Step 2: Of those, also get only the bars that they also frequent. Πd-name(likes serves frequents)

Example #3, Query #3 Πd-name(likes serves frequents) Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #3: Which drinkers frequent a bar that serves a beer they like? First join is drinker,beer,bar such that drinker likes a beer and the bar serves that beer. Second join strips out the triples that had a bar that the drinker does not frequent. Step 2: Of those, also get only the bars that they also frequent. Πd-name(likes serves frequents)

Example #3, Query #3 Πd-name(likes serves frequents) Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #3: Which drinkers frequent a bar that serves a beer they like? First join is drinker,beer,bar such that drinker likes a beer and the bar serves that beer. Second join strips out the triples that had a bar that the drinker does not frequent. Step 3: Extract the drinkers. Πd-name(likes serves frequents)

Example #3, Query #3 Πd-name(likes serves frequents) Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #3: Which drinkers frequent a bar that serves a beer they like? First join is drinker,beer,bar such that drinker likes a beer and the bar serves that beer. Second join strips out the triples that had a bar that the drinker does not frequent. Step 3: Extract the drinkers. Πd-name(likes serves frequents)

Example #3, Query #3 Πd-name(likes serves frequents) Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #3: Which drinkers frequent a bar that serves a beer they like? First join is drinker,beer,bar such that drinker likes a beer and the bar serves that beer. Second join strips out the triples that had a bar that the drinker does not frequent. Πd-name(likes serves frequents)

Example #3, Query #4 Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #4: Which drinkers don’t frequent any bar that serves a beer they like? All drinkers except the ones that frequent a bar that serves a beer they like. Then it’s the opposite of query #3.

Example #3, Query #4 Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #4: Which drinkers don’t frequent any bar that serves a beer they like? All drinkers except the ones that frequent a bar that serves a beer they like. Then it’s the opposite of query #3. Steps to take? Compute the drinkers that do frequent a bar that serves a beer they like. Compute the opposite of those.

Example #3, Query #4 Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #4: Which drinkers don’t frequent any bar that serves a beer they like? All drinkers except the ones that frequent a bar that serves a beer they like. Then it’s the opposite of query #3. Steps to take? Compute the drinkers that do frequent a bar that serves a beer they like. Compute the opposite of those.

Example #3, Query #4 Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #4: Which drinkers don’t frequent any bar that serves a beer they like? All drinkers except the ones that frequent a bar that serves a beer they like. Then it’s the opposite of query #3. Steps to take? Compute the drinkers that do frequent a bar that serves a beer they like. Compute the opposite of those.

Example #3, Query #4 Πd-name(drinker) – Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #4: Which drinkers don’t frequent any bar that serves a beer they like? Step 1: Compute the drinkers that do frequent a bar that serves a beer they like. Πd-name(drinker) – Πd-name(likes serves frequents)

Example #3, Query #4 Πd-name(drinker) – Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #4: Which drinkers don’t frequent any bar that serves a beer they like? Step 1: Compute the drinkers that do frequent a bar that serves a beer they like. Πd-name(drinker) – Πd-name(likes serves frequents)

Example #3, Query #4 Πd-name(drinker) – Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #4: Which drinkers don’t frequent any bar that serves a beer they like? Step 2: Compute the opposite of those. Πd-name(drinker) – Πd-name(likes serves frequents)

Example #3, Query #4 Πd-name(drinker) – Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #4: Which drinkers don’t frequent any bar that serves a beer they like? Step 2: Compute the opposite of those. Πd-name(drinker) – Πd-name(likes serves frequents)

Example #3, Query #4 Πd-name(drinker) – Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #4: Which drinkers don’t frequent any bar that serves a beer they like? Πd-name(drinker) – Πd-name(likes serves frequents)

Example #3, Query #5 Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #5: Which drinkers frequent only bars that serve some beer they like? All drinkers except the ones that frequent some bar that doesn’t serve any beer they like.

Example #3, Query #5 Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #5: Which drinkers frequent only bars that serve some beer they like? All drinkers except the ones that frequent some bar that doesn’t serve any beer they like. Steps to take? Compute drinkers with bars that serve a beer they like. Take those out of frequents (gives us drinkers that frequent a bar that don’t serve a beer they like). Take those out of drinker.

Example #3, Query #5 Relational Schema: DRINKER(d-name,d-city) BAR(ba-name,ba-city) BEER(be-name,type) FREQUENTS(d-name,ba-name) SERVES(ba-name,be-name) LIKES(d-name,be-name) Query #5: Which drinkers frequent only bars that serve some beer they like? Opposite of: Drinkers that frequent some bar that don’t serve a beer they like. All drinkers except the ones that frequent some bar that doesn’t serve any beer they like. Steps to take? Compute drinkers with bars that serve a beer they like. Take those out of frequents (gives us drinkers that frequent a bar that don’t serve a beer they like). Take those out of drinker.