Relations and Relational Algebra
Relations and Relational Algebra
RELATIONAL ALGEBRA
Lecture 2
Relations
Alice [email protected]
Cathy [email protected]
Relations
Alice [email protected]
Cathy [email protected]
Relations
■ A mathematician would say that it is a set of
pairs
– < Alice, aaa @ abc.com>
– < Ben, bbb @ abc.com>
– < Cathy, ccc @ abc.com>
Alice [email protected]
Cathy [email protected]
Relations
■ Each value in the first column is a name, each value in
the second column is an email address
■ In general, each column has a domain
– a set from which all possible values can come
Alice [email protected]
Cathy [email protected]
Relations
■ A mathematical relation is a set of tuples: sequences of
values
■ Each tuple corresponds to a row in a table
R S R S
R S R S
R S R S
R:
1 2 3
Alice 0115111111
Ben 0115222222
Cathy 0115333333
Example: 2,3 ( R)
[email protected]
0115111111 0115111111
[email protected]
0115222222 0115222222
[email protected]
0115333333 0115333333
Selection
■ Let R be a relation with n columns, and is a property
represented as a condition
■ Selection from R, subject to condition is defined as
follows:
(R) , which is the set of rows from R that satisfy the
condition
What is a meaningful comparison
■ is a comparator which makes sense when applied to
values from i and j columns (= , , maybe also , , ,
if there is a natural order on values)
■ We can always at least tell if two values in the same
domain are equal or not (database values are finitely
represented)
■ In some cases, it makes sense to compare values from
different column domains; for example, if both are
domains contain strings, or both contain dates
■ For example, 1975 > 1987 is a meaningful comparison,
“Anne” = 1981 is not
■ We can only use a comparison in selection property if its
result is true or false, never undefined
Example: selection
R S
Anne 111111 Chris 333333