The r × s combines every tuple of r with every tuple of s:
r
| a |
|---|
| 1 |
| 2 |
s
| b |
|---|
| x |
| y |
| z |
r × s
| a | b |
|---|---|
| 1 | x |
| 1 | y |
| 1 | z |
| 2 | x |
| 2 | y |
| 2 | z |
- The schema is every attribute of
r, then every attribute ofs. - When both have an attribute with the same name, write the relation name in front:
instructor.id,teaches.id. - The size is
|r| × |s|. (|r|is the number of tuples ofr.)
In SQL, use CROSS JOIN or a comma (Chapter 8):
sql
SELECT * FROM department CROSS JOIN course;Product, then selection
Most pairs in a product do not belong together. σ keeps the pairs that do:
text
σ instructor.id = teaches.id (instructor × teaches)This pairs each instructor with the rows of teaches that have the same id.
The same relation twice
To pair a relation with itself, rename at least one copy, so each attribute has a different full name:
text
σ a.building = b.building (ρ a (department) × ρ b (department))