Relational Algebra 1
Relational Algebra 1
Relational Algebra 1
attributes
(or columns)
tuples
(or rows)
Attribute
• select:
• project:
• union:
• set difference: –
• Cartesian product: x
• rename:
Select Operation
The select operation selects tuples that satisfy a given predicate.
Notation: p(r)
p is called the selection predicate
Example: select those tuples of the instructor relation where the
instructor is in the “Physics” department.
• Query
• Result
Select Operation (Cont.)
We allow comparisons using
=, , >, . <.
in the selection predicate.
We can combine several predicates into a larger predicate by using the
connectives:
(and), (or), (not)
Example: Find the instructors in Physics with a salary greater $90,000,
we write:
Thus
instructor.id = teaches.id (instructor x teaches ))
Result of:
x (E)
returns the result of expression E under the name x
Another form of the rename operation:
Query 2
The two queries are not identical; they are, however, equivalent --
they give the same result on any database.
Equivalent Queries
There is more than one way to write a query in relational algebra.
Example: Find information about courses taught by instructors in
the Physics department
Query 1
Query 2
The two queries are not identical; they are, however, equivalent --
they give the same result on any database.