The Union Operation
Consider a
query to find the names of all bank customer ids who have either an account or
a loan or both. Note that the customer relation does not contain the
information but to answer this query, we need to extract information from both
the deposit and borrow relations:
We know how to
find the names of all customers with a loan in the bank:
We also know
how to find the names of all customers with an account in the bank:
To answer the
query we need the union of these two sets; that is, we need all customer names
that appear in either or both of the two relations. So we write:
The Set-Difference Operation
The
set-difference operation, denoted by -, allows us to find tuples that are in
one relation but are not in another. The expression r-s produces a relation
containing those tuples in r but not in s.
We find all
customer ids of the bank who have an account but not a loan by writing:
The Set-Intersection Operation
The
set-intersection operation is denoted by ∩.
Suppose that we wish to find all customers who have both a loan and an account.
Using set intersection, we can write:
No comments:
Post a Comment