Relational Algebra
Relational algebra is a language to describe relations.
Two categories:
Core:
Abbreviation:
Select operator:
Select operator in RA is like Where syntax in SQL:
It is used to select rows and filter the original relationship:
Project operator:
It is like the select syntax in SQL:
It is used to select columns in a relationship:
Also, it will eliminate the duplicate rows
Cross-product:
Full outer Join in SQL
Can achieve natural join effect by applying one more select operator
Natural Join
Natural Join in SQL
more efficient than cross product
Section 1 summary
Union
full outer join on just one same column
it is euqal to the following SQL:
select student.id from student fuller outer join record on student.id = record.stu.id
Different
left outer join on just one same column and b.key is null
it is equal to the following SQL:
select student.id from student left outer join record on student.id = record.stu.id where record.stu.id = NULL
Intersection
inner join on just one single column,
equal to the following SQL:
select student.id from student join record
intersection just being convenient, does not add new ability. it is equal to natrual join.
Rename Operator
useful in union, different and intersection
useful in self-join
e.g. find pairs in the same table
alternative notation
Two different other ways to write the relational algebra