Chapter 1: Information Technology - RPI CS

Rensselaer Polytechnic Institute
CSCI-4380 – Database Systems
David Goldschmidt, Ph.D.

Find and select all tuples from relation R
that satisfy some set of conditions
 Forms the basis of querying a database
 The selection C (R) is based on Boolean
condition C over attributes of relation R
 Example conditions include:
▪ A = e, A > e, A >= e, A < e, A <= e, A <> e
▪ A1 = A2, A1 <> A2
▪ Any combination of conditions using AND, OR, NOT

Selection selects a subset of tuples in
relation R (with the schema unchanged)


(R)
= { t | t is a tuple in R and t satisfies the
condition C on relation R }
C
 Selection conditions can only refer to
attributes in the given relation R
 For conditions spanning multiple relations, we
first must combine those relations (i.e. join)

The Cartesian product combines
two relations to form a new relation
 The new relation has all of the attributes
of the original two relations
 It’s often a good idea to rename attributes
in the original relations such that
there’s no ambiguity

Given two relations R and S with
schemas R(A1,A2,...,An) and S(B1,B2,...,Bm)
 The Cartesian product RxS produces
relation T with schema T(A1,A2,...,An,B1,B2,...,Bm)
 We can disambiguate attributes
by using R.Ax and S.By
▪ i.e. attributes Ax and By have the same name

The Cartesian product of relations R and S:
 RxS = { (r,s) | r is a tuple in R and s is a tuple in S }
▪ Note that (r,s) has all values in r and s
 The Cartesian product is like multiplication
in that it produces a tuple for every pair of
tuples from R and S
▪ e.g. if R has 10 tuples and S has 5 tuples,
then RxS will have 50 tuples

Cartesian product RxS is often followed by a
selection condition that specifies how tuples
in R should be matched to tuples in S


name=student
(Undergraduate x Advising)
 Translation: Join the Undergraduate and
Advising relations by selecting tuples in which
the name attribute equals the student attribute

When joining two relations, we often want
to join on common (same-named) attributes
 This is a natural join on relations R and S
and is denoted R⋈S
 The selection condition selects tuples that have
the same values for same-named attributes
 Note that the schema does not repeat the
same-named attributes

Joins based on specific conditions are
called theta joins and are denoted R ⋈C S
 To perform a theta join, first take the
product of relations R and S
 Next, select tuples that satisfy condition C
 The resulting schema is the union of the
schemas of R and S with R.Ax and S.By prefixes,
if necessary

The rename operator changes the
name of the attributes of relation R
with schema R(A1,A2,...,An)


( R)
= relation S(B1,B2,...,Bn) in
which R.A1 is renamed S.B1, R.A2 is renamed S.B2,
and so on
 To only change some attribute names,
simply specify Bi = Ai
S(B1,B2,...,Bn)

Find all faculty who advise a student

Find all faculty who do not advise
any students

Find faculty who advise at least two
students

Find faculty who advise a student that is not
in their department (e.g. dual majors)