Basic Operations

Select $\sigma$

  • specifies the tuples to retain through a selection condition which is a Boolean combination

Project $\Pi$

  • Return: extract columns from a relation by specifying the field to be retained
  • the duplicated row will be eliminated

Rename $\rho$

  • Return: a relation named R

  • E: relation algebra expression

  • F: renaming list
    • oldname → newname
      • $ \rho \space ( \space C ( sid → identity, \space child → dependent ), \space E )$
    • position → newname
      • $ \rho \space ( \space C ( 3 → identity), \space E )$

Sets Operations

Union $R \cup S$

  • **Return**: a relation instance containing all tuples that occurs in either relation instance R or S
  • the duplicated row will be eliminated

  • Two relation instances must be union-compatible

    • They have same number of fields
    • The corresponding fields have the same domains

Set Different $R - S$

  • **Return**: a relation instance containing all the tuples that occurs in R but not in S
  • Two relation instances must be union-compatible

Set Intersection $R \cap S$

  • **Return**: a relation instance containing all tuples that occurs in both R and S
  • Two relation instances must be union-compatible

Corss & Join

Cartesian Product

  • Return: a relation instance whose schema contains all the fields of R followed by all the fields of S

  • Situation: Comparation in different entity seys

    1. Select the female employees and project the f_name, l_name and id to Empnames

    2. FemaleEmps cross Empnames, such that they are able to compare in a table (entity)

    3. Choose the row that has the same id and did and project the f_name, l_name and dep_name onto Results

Condition Join $\Join$

  • Cartesian product with selection

  • Situation: Find maximum

    1. Select the employees whose salary is not the greatest

    2. Different (Remove the selected employee)

Equi Join

  • the join condition consists solely of equalities

Natural Join

  • An equi join in which equalities are specified on all fields having the same names in R and S

Division

  • The division operation is useful for expressing certain kinds of queries
  • Example: find the names of sailors who have reserved all boats