SLIDE 1
1
CSPP 53001: Databases
Svetlozar Nestorov
Class News
- HW2 due on Monday
– email SQL scripts to Xueyuan
- HW3 will be out this weekend
- Midterm in first half of class on November 5
(5:15pm - 6:45pm)
– open book/notes
Overview
- Multirelation SQL queries
- Subqueries
- Aggregation
- Schema declarations
- Modifications
Multirelation Queries
- List of relations in the FROM clause
- Relation-dot-attribute disambiguates
attributes with the same name from several relations.
- Example: find all
beers that Hopleaf regulars like. Frequents(drinker,bar) Likes(drinker,beer)
Formal Semantics
1. Start with the product of all relations in the FROM clause. 2. Apply σ (bag), using condition in WHERE clause. 3. Apply π (extended, bag) using attributes in the SELECT clause. The same as single-relation query with the addition of product of all relations.
Equivalent Operational Semantics
- Consider a tuple variable for each relation
in the FROM clause
- Imagine a series of nested loops over these
variables that produces every possible combination of tuples, one from each of the relations in the FROM clause.
- 1. For each tuple combination, check if it
satisfies the WHERE clause
- 2. If so, print the values of terms in the