Professional Documents
Culture Documents
Evaluation Slides 6
Evaluation Slides 6
Principal form:
desired attributes
tuple variables |
range over relations
WHERE condition about t.v.'s;
Running example relation schema:
SELECT
FROM
Beers(name, manf)
Bars(name, addr, license)
Drinkers(name, addr, phone)
Likes(drinker, beer)
Sells(bar, beer, price)
Frequents(drinker, bar)
Example
name
Bud
Bud Lite
Michelob
manf
Anheuser-Busch
Anheuser-Busch
Anheuser-Busch
Renaming columns
Beers(name, manf)
SELECT name AS beer
FROM Beers
WHERE manf = 'Anheuser-Busch';
beer
Bud
Bud Lite
Michelob
bar
Joe's
Sue's
beer
Bud
Miller
priceInYen
300
360
drinker whoLikesBud
Sally likes Bud
Fred likes Bud
Example
Patterns
% stands for any string.
stands for any one character.
\Attribute LIKE pattern" is a condition that
is true if the string value of the attribute
matches the pattern.
Also NOT LIKE for negation.
Example
';
Nulls
10
Example
bar
Joe's bar
beer
Bud
price
NULL
SELECT bar
FROM Sells
WHERE price < 2.00 OR price >= 2.00;
-----------------------UNKNOWN
UNKNOWN
-----------------------UNKNOWN
condition is a tautology.
11
3-Valued Logic
12
Multirelation Queries
List of relations in FROM clause.
Relation-dot-attribute disambiguates
attributes from several relations.
Example
13
Operational Semantics
14
drinker bar
Sally
drinker beer
Sally
Joe's
Likes
Frequents
15
Example
16
Subqueries
The IN Operator
Example
Also:
NOT IN
18
EXISTS
Example
Quantiers
ANY
Example
Class Problem
20