s
Section 5.3 Relations and Databases
371
result as a set of (n + k − 1)-tuples (the common attribute is written only once).
Join is therefore not really a separate operation but is defined as the result of doing
a Cartesian product followed by a restrict.
example 24
The operation
join Person and PetOwner over Name giving Listing
results in the Listing relation.
listing
Name
address
city
State petName petType Breed
Smith, Mary 1121 Ridge Rd. Rockville IL
Twinkles
Cat
Siamese
Collier, Jon
429 Via Rivio
Venice
IL
Tweetie
Bird
Canary
Jones, Kate 345 Forest St. Cleveland OH
Lad
Dog
Collie
Jones, Kate 345 Forest St. Cleveland OH
Lassie
Dog
Collie
Smith, Bob 1201 45th St.
Falls City MA
Spot
Dog
Hound
White, Janet 110 Toledo Rd. Brookville GA
Tiger
Cat
Shorthair
The restrict, project, and join operations can be applied in various combinations to formulate queries that the user wishes to perform on the database. For
example, suppose the query is
Give the names of all cats whose owners live in Illinois.
(1)
If the only existing relations are Person and PetOwner, the following sequence of
operations will produce a relation that answers this query:
restrict PetOwner where PetType = “Cat” giving Results1
Results1
Name
petName
petType
Breed
Smith, Mary
Twinkles
Cat
Siamese
White, Janet Tiger
Cat
Shorthair
restrict Person where State = “IL” giving Results2
Results2
Name
address
city
State
Smith, Mary 1121 Ridge Rd. Rockville
IL
Collier, Jon
429 Via Rivio
Venice
IL
Précédent

- 388/986

Suivant